pushbotton1是畫圖的,pushbutton2是清除的,你要做一個數據傳遞的工作,因為callback中的變數都是區域性變數:
function pushbutton1_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)
a=0:0.01:pi;
ax1=SUBPLOT(2,1,1);plot(a,sin(a));
ax2=SUBPLOT(2,1,2);plot(a,cos(a));
setappdata(handles.pushbutton1,"ax1",ax1)
setappdata(handles.pushbutton1,"ax2",ax2)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
ax1=getappdata(handles.pushbutton1,"ax1");
ax2=getappdata(handles.pushbutton1,"ax2");
cla(ax1)
cla(ax2)
pushbotton1是畫圖的,pushbutton2是清除的,你要做一個數據傳遞的工作,因為callback中的變數都是區域性變數:
function pushbutton1_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)
a=0:0.01:pi;
ax1=SUBPLOT(2,1,1);plot(a,sin(a));
ax2=SUBPLOT(2,1,2);plot(a,cos(a));
setappdata(handles.pushbutton1,"ax1",ax1)
setappdata(handles.pushbutton1,"ax2",ax2)
% --- Executes on button press in pushbutton2.
function pushbutton2_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)
ax1=getappdata(handles.pushbutton1,"ax1");
ax2=getappdata(handles.pushbutton1,"ax2");
cla(ax1)
cla(ax2)