In der Vergangenheit habe ich Matlab 2013 verwendet und dieser Code läuft korrekt und keine Fehler, aber jetzt verwende ich Matlab r2015a und wenn ich den Code ausführen, erhalte ich den folgenden Fehler: Cannot convert double value -10 to a handle.
Ich habe die Matworks-Website überprüft, aber die Erklärung ist nicht sehr klar. Haben Sie Vorschläge, wie Sie das beheben können? Ich danke dir sehr !Matlab r2015a Anleitung - kann nicht doppelt zu einem Griff konvertieren
function minhhoaxy(action,in1)
global DATA;
if nargin < 1,
action='start';
end;
if strcmp(action,'start'),
clf reset;
figure(gcf);
set(gcf,'Units','normalized','NumberTitle','off', ...
'Name','Minh hoa GUI','backingstore','on');
min_x=-10;
max_x=10;
x=0;
uicontrol('Style','text','Units','normalized',...
'Position',[.03 .03 .1 .05],...
'BackgroundColor',[0 0.5 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'ForegroundColor','white','String','Vò trí x:',...
'HorizontalAlignment','center');
uicontrol('Style','text','Units','normalized',...
'Position',[.15 .03 .05 .05],...
'BackgroundColor',[0 0 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'HorizontalAlignment','center',...
'ForegroundColor','white','String',num2str(min_x));
x1=uicontrol('Style','slider','Units','normalized',...
'Position',[.2 .03 .25 .05],...
'SliderStep',[5.0000e-004 5.0000e-003],...
'Value',x,'Max',max_x,'Min',min_x,...
'Callback','minhhoaxy(''setx'',1);minhhoaxy(''redraw'');');
uicontrol('Style','text','Units','normalized',...
'Position',[.45 .03 .05 .05],...
'BackgroundColor',[0 0 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'HorizontalAlignment','center',...
'ForegroundColor','white','String',num2str(max_x));
x2=uicontrol('Style','edit','Units','normalized',...
'Position',[.55 .03 .09 .05],...
'FontSize',10','Fontname','VNI-Times',...
'String',num2str(x),...
'Callback','minhhoaxy(''setx'',2);minhhoaxy(''redraw'')');
uicontrol('Style','text','Units','normalized',...
'Position',[.64 .03 .05 .05],...
'BackgroundColor',[0 0 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'ForegroundColor','white','String','cm',...
'HorizontalAlignment','center');
uicontrol('Style','Pushbutton','Units','normalized',...
'Position',[.87 .03 .1 .05],...
'FontSize',12,'Fontname','VNI-Times',...
'Callback','minhhoaxy(''done'')','String','Thoaùt');
min_y=-10;
max_y=10;
y=0;
uicontrol('Style','text','Units','normalized',...
'Position',[.03 .1 .1 .05],...
'BackgroundColor',[0 0.5 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'ForegroundColor','white','String','Vò trí y:',...
'HorizontalAlignment','center');
uicontrol('Style','text','Units','normalized',...
'Position',[.15 .1 .05 .05],...
'BackgroundColor',[0 0 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'HorizontalAlignment','center',...
'ForegroundColor','white','String',num2str(min_y));
uicontrol('Style','text','Units','normalized',...
'Position',[.45 .1 .05 .05],...
'BackgroundColor',[0 0 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'HorizontalAlignment','center',...
'ForegroundColor','white','String',num2str(max_y));
uicontrol('Style','text','Units','normalized',...
'Position',[.64 .1 .05 .05],...
'BackgroundColor',[0 0 .5],...
'FontSize',12,'Fontname','VNI-Times',...
'ForegroundColor','white','String','cm',...
'HorizontalAlignment','center');
y1=uicontrol('Style','slider','Units','normalized',...
'Position',[.2 .1 .25 .05],...
'SliderStep',[5.0000e-004 5.0000e-003],...
'Value',y,'Max',max_y,'Min',min_y,...
'Callback','minhhoaxy(''sety'',1);minhhoaxy(''redraw'');');
y2=uicontrol('Style','edit','Units','normalized',...
'Position',[.55 .1 .09 .05],...
'FontSize',10','Fontname','VNI-Times',...
'String',num2str(y),...
'Callback','minhhoaxy(''sety'',2);minhhoaxy(''redraw'')');
dt=plot(x,y,'r.','EraseMode','xor','Markersize',50);
axis([-10 10 -10 10]);
grid;
DATA=[x;min_x;max_x;x1;x2;dt;y;min_y;max_y;y1;y2];
elseif strcmp(action,'redraw'),
x=DATA(1);
dt=DATA(6);
set(DATA(5),'string',num2str(x));
set(DATA(4),'value',x);
y=DATA(7);
set(DATA(11),'string',num2str(y));
set(DATA(10),'value',y);
set(dt,'XData',x);
set(dt,'YDATA',y);
drawnow;
elseif strcmp(action,'setx'),
if (in1==1),
DATA(1)=get(DATA(4),'value');
else
min_x=DATA(2);
max_x=DATA(3);
x=str2double(get(DATA(5),'string'));
if (x>max_x),
x=max_x;
end;
if (x<min_x),
x=min_x;
end;
DATA(1)=x;
end
elseif strcmp(action,'sety'),
if (in1==1),
DATA(7)=get(DATA(10),'value');
else
min_y=DATA(8);
max_y=DATA(9);
y=str2double(get(DATA(11),'string'));
if (y>max_y),
y=max_y;
end;
if (y<min_y),
y=min_y;
end;
DATA(7)=y;
end
elseif strcmp(action,'done'),
clf reset;
clear global DATA
close;
end
Geben Sie die * vollständige * Fehlermeldung ein. Darüber hinaus ist dieser Code fürchterlich verwirrend. Warum generieren Sie alle Ihre UI-Objekte zweimal? Und setzen Sie Ihre Handles nicht in ein Array mit anderen zufälligen Doppelpunkten und referenzieren Sie das Array später. Verwenden Sie einfach die Handles in Ihren 'set' Aufrufen oder speichern Sie die Handles zu Ihren Objekten in ihrem * eigenen * Array mit expliziten Namen, so dass Sie wissen, was Sie verwenden, ohne zurückzugehen und Ihre' DATA'-Zuweisungen jedes Mal zu referenzieren. – excaza
Beginnend in R2014b, [Grafikgriffe sind jetzt Objekte, nicht doppelt] (http://www.mathworks.com/help/matlab/graphics_transition/graphics-handles-are-now-objects-not-doubles.html?refresh= wahr). Diese – excaza
ist voll Fehlermeldung: ‚> In minhhoaxy (Zeile 96) Fehler mit matlab.ui.control.UIControl/vertcat nicht den doppelten Wert umwandeln kann -10 mit einem Griff Fehler in minhhoaxy (Linie 99) DATA = [x; min_x; max_x; x1; x2; dt; y; min_y; max_y; y1; y2]; '' –