MATLAB Answers

R Hebi

save GUI fig by name from edit text

R Hebi
さんによって質問されました 2019 年 11 月 15 日 18:28
最新アクティビティ Rik
さんによって 編集されました 2019 年 11 月 15 日 21:02
I am trying to save a figure in GUI, I want when the user click on a push button the below window appear.
I applied the follwoing function:
filter = {'*.m';'*.emf';'*.*'};
[file, path] = uiputfile(filter);
but when I press (save) nothing is saved. The problem is how to connect my figure to the above function.

  4 件のコメント

Adam Danz
2019 年 11 月 15 日 19:00
Abdullah Alraigi,'s answer moved here as a comment
The figure is embeded with GUI
I used Guide
2019 年 11 月 15 日 19:06
Note that copying the figure is not going to copy the callbacks, so you will end up with a figure that is only a visual copy of your GUI but no longer has any functionality.
Adam Danz
2019 年 11 月 15 日 19:14
I was worried about that too but it turns out that the goal was to copy the embedded axes onto an external figure.

サインイン to comment.

1 件の回答

Adam Danz
回答者: Adam Danz
2019 年 11 月 15 日 18:59

Place this code in a callback function designed to save the figure. See inline comments for details.
newFig = figure(); % Create a new parent figure
newAx = copyobj(handles.axes1, newFig); % Copy your GUI axis to the new figure
% ^^^^^^^^^^^^^ Put your axis handle here
% Reposition the axis to default position within the new figure
newAx.Units = 'Normalize';
newAx.Position = [.13, .11, .76, .82];
% Ask user for path and filename
[file, path] = uiputfile('.fig');
% Save figure and print out a confirmation.
fprintf('Figure saved: %s\n', file) % optional

  2 件のコメント

Adam Danz
2019 年 11 月 15 日 19:11
Abdullah Alraigi's answer moved here as a comment.
Thx adam
it works as wanted
Adam Danz
2019 年 11 月 15 日 19:12
Just a small request - in the future, try to use the comments section for discussion and reserve the answer section for answers.
Glad I could help! ;)

サインイン to comment.

Translated by