从函数中调用图表以在GUI中显示

时间:2013-07-04 10:18:14

标签: matlab user-interface

我有这些功能和一个带有两个轴(axis3和axes4)的GUI和两个编辑文本和一个按钮。

function z=add(x,y)
z=x+y;
end

function z=mul(x,y)
z=x*y;
end

function pre(z1,z2)
plot(handles.axes3,z1,'b*');
set(get(handles.axes3,'Title'),'String','Number of Iterations');
set(get(handles.axes3,'XLabel'),'String','Number of Comlpeted Tours');
set(get(handles.axes3,'YLabel'),'String','MIN of Lenght of Tours');

plot(handles.axes4,z2,'r*');
set(get(handles.axes4,'Title'),'String','Number of Iterations');
set(get(handles.axes4,'XLabel'),'String','Number of Comlpeted Tours');
set(get(handles.axes4,'YLabel'),'String','MIN of Lenght of Tours');
end

function main(x,y)
z1=add(x,y);
z2=mul(x,y);
pre(z1,z2);
end

function pushbutton1_Callback(hObject, eventdata, handles)
x=str2double(get(handles.edit1_x,'String'));
y=str2double(get(handles.edit2_y,'String'));
main(x,y);

我有这个错误:

??? Undefined variable "handles" or class "handles.axes3".
Error in ==> main at 6
        plot(handles.axes3,z1,'b*');

如何通过调用pre(z1,z2)?

来显示GUI中的轴输出

1 个答案:

答案 0 :(得分:0)

如果你不给它句柄,pre()如何访问句柄?我认为这可以解决它。

function z=add(x,y)
z=x+y;
end

function z=mul(x,y)
z=x*y;
end

function pre(z1,z2,handles)
plot(handles.axes3,z1,'b*');
set(get(handles.axes3,'Title'),'String','Number of Iterations');
set(get(handles.axes3,'XLabel'),'String','Number of Comlpeted Tours');
set(get(handles.axes3,'YLabel'),'String','MIN of Lenght of Tours');

plot(handles.axes4,z2,'r*');
set(get(handles.axes4,'Title'),'String','Number of Iterations');
set(get(handles.axes4,'XLabel'),'String','Number of Comlpeted Tours');
set(get(handles.axes4,'YLabel'),'String','MIN of Lenght of Tours');
end

function main(x,y,hanldes)
z1=add(x,y);
z2=mul(x,y);
pre(z1,z2,handles);
end

function pushbutton1_Callback(hObject, eventdata, handles)
x=str2double(get(handles.edit1_x,'String'));
y=str2double(get(handles.edit2_y,'String'));
main(x,y,handles);