function pushbutton_SaveasImg_Callback(hObject, eventdata, handles)
Fig1 = figure('Units','normalized','Position',[0.1 0.1 0.8 0.8]);
set(Fig1,'Visible','off');
find_leg = findobj(handles.axes4,'tag','legend');
legendstr=get(find_leg,'String');
newAxes = copyobj(handles.axes4,Fig1);
set(newAxes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
legend(newAxes,legendstr,'Location','northeast');
[FileName,PathName] = uiputfile( ...
{'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files (*.*)'});
if isequal(FileName,0) || isequal(PathName,0)
disp('User Clicked Cancel.')
else
disp(['User selected ',fullfile(PathName,FileName),...
' and then clicked Save.'])
saveas(Fig1, FileName);
close(Fig1);
end
Best Answer