Save (Axes) As in GUI

7 ビュー (過去 30 日間)
R Hebi
R Hebi 2019 年 11 月 25 日
コメント済み: Ankit 2019 年 11 月 25 日
Hi,
I am using Matlab GUI (guide) to do some calculation and the results appear as a curve in figure (axes1). I would like to save the figure of this curve.
I created a push button (pushbutton1), and I inserted many different codes the problem with most of them are
  1. It saves the whole GUI window not only the (axes1)
  2. When the save window is opened to wirte the file name/path, if the user click on cancel it will break down and an eeror is appearing
Thx

採用された回答

Ankit
Ankit 2019 年 11 月 25 日
編集済み: Ankit 2019 年 11 月 25 日
Updated!
Based on your comment I updated the answer
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'); % axes4 is the name of your Axes
% retrieve the legend strings
legendstr=get(find_leg,'String');
newAxes = copyobj(handles.axes4,Fig1); % Copy the appropriate axes
set(newAxes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
% recreate the legend
legend(newAxes,legendstr,'Location','northeast');
% Save as Image file.
[FileName,PathName] = uiputfile( ...
{'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files (*.*)'});
% 2. When the save window is opened to write the file name/path,
% if the user click on cancel it will break down and an error is appearing
% below code avoid the error you are getting
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
  2 件のコメント
R Hebi
R Hebi 2019 年 11 月 25 日
Thx
But his will save directly rather than have option to add a file name & format
I would like to do it using (uiputfile) if that is possible.
Thx again
Ankit
Ankit 2019 年 11 月 25 日
I updated the answer based on your feedback! You can add the file extension based on your requirements!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by