方法如下:
创建一个GUI
画好了就如下图。
直接放代码了:
重点处加粗了。
% --- Executes on button press in pushbutton2.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t = -5:.1:5
y = sinc(t)
plot(handles.axes1,t,y,'gd')
legend(handles.axes1,'sin(x)/x'闭正晌)
% --- Executes on button press in pushbutton1.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t = 1:.1:10
x = sin(t)
y = cos(t)
plot3(handles.axes2,t,x,y,'r*')
legend(handles.axes2,'t-x-y')
3
plot(handles.axes1,t,y,'gd')
plot3(handles.axes2,t,x,y,'r*'轿锋)
关键的就是这两句了清答,其它情况也是类似的。
结果就如下了
修改你的作图程序,增加一个输入参数,将axes的句柄传递给函数森祥纳或者在调用作图函数之前将用set函数将gca(当前激活的axes)设为你想要的axes句宴拍柄
再调用左图函数,而你的作图函数应该指定此没在gca中画图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)