save GUI fig by name from edit text

1 view (last 30 days)
R Hebi
R Hebi on 15 Nov 2019
Edited: Rik on 15 Nov 2019
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.
Adam Danz
Adam Danz on 15 Nov 2019
I was worried about that too but it turns out that the goal was to copy the embedded axes onto an external figure.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 15 Nov 2019
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
Adam Danz
Adam Danz on 15 Nov 2019
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! ;)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by