用print命令实现:
% "存"按钮回调函数
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)
[filename pathname]=uiputfile({'*.png','png file(*.png)'});
fullName = [pathname filename];
h = handles.figure1;
h2 = get(h,'Children');
%隐藏两个按钮
set(h2(3),'Visible','off');
set(h2(4),'Visible','off');
print(h,'-dpng',fullName);
%恢复两个按钮
set(h2(3),'Visible','on');
set(h2(4),'Visible','on');
保存图片: