Hi
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
Adam Danz 2019년 11월 15일
Is the figure external to your GUI or is embedded within your gui?
How did you create the GUI - with guide or app designer?
Adam Danz
Adam Danz 2019년 11월 15일
Abdullah Alraigi,'s answer moved here as a comment
The figure is embeded with GUI
I used Guide
Rik
Rik 2019년 11월 15일
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
Adam Danz 2019년 11월 15일
I was worried about that too but it turns out that the goal was to copy the embedded axes onto an external figure.

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2019년 11월 15일

0 개 추천

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.
savefig(fullfile(path,file));
fprintf('Figure saved: %s\n', file) % optional

댓글 수: 2

Adam Danz
Adam Danz 2019년 11월 15일
Abdullah Alraigi's answer moved here as a comment.
Thx adam
it works as wanted
Adam Danz
Adam Danz 2019년 11월 15일
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! ;)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2019년 11월 15일

편집:

Rik
2019년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by