How to save an axes within a GUI to a .fig

조회 수: 52 (최근 30일)
Daniel Green
Daniel Green 2017년 8월 9일
댓글: Daniel Green 2017년 8월 10일
When I try this:
[FileName,PathName] = uiputfile;
saveDataName = fullfile(PathName,FileName);
saveas(handles2.axes9,saveDataName);
It saves a file, but when I open the file, it is just another GUI. It is saving an iteration of my GUI when I only want it to save "handles2.axes9" to a ".fig" Help?
  댓글 수: 3
Daniel Green
Daniel Green 2017년 8월 9일
I want to save a figure of the axes. Instead, this block of code is resaving my GUI's figure, with the variables/handles that were present when the user hit save. Plotted on "handles2.axes9" is an imagesc created from a .mat the user has already selected. I just want it so the user clicks the save button in the toolbar and it saves the imagesc within handles2.axes9 as well as the title/labeling that is present to a .fig.
Jan
Jan 2017년 8월 9일
For Matlab programmers, a "figure" is usually the window, which is created by the command figure. An "axes" is the axes box with the tick-lables and the contents drawn into a figure. Then what does "save a figure of the axes" mean? The saveas command saves the figure and then it contains the other data also. This is the meaning of a .fig file. Therefore I still do not know, what you want to solve. There is no way to save a .fig file without the data, which belong to .fig files.
Do you want a screen shot as .png file? Could you create an example image of what you want?

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

채택된 답변

Teja Muppirala
Teja Muppirala 2017년 8월 10일
This might work. You create a new (temporary and invisible) figure, and then use COPYOBJ to copy that axes to the new figure. You could then save the new figure to a FIG file (here "test.fig").
%%1. Make sample figure
handles.f = figure;
handles.axes1 = subplot(211);
handles.axes2 = subplot(223);
handles.axes3 = subplot(224);
plot(handles.axes1,rand(5));
imagesc(handles.axes2,rand(10,10));
title(handles.axes2, 'My IMAGESC');
xlabel(handles.axes2,'X values');
ylabel(handles.axes2,'Y values');
surf(handles.axes3,peaks);
%%2. Copy axes to new figure and save
outputFileName = 'test.fig';
fignew = figure('Visible','off'); % Invisible figure
newAxes = copyobj(handles.axes2,fignew); % Copy the appropriate axes
set(newAxes,'Position',get(groot,'DefaultAxesPosition')); % The original position is copied too, so adjust it.
set(fignew,'CreateFcn','set(gcbf,''Visible'',''on'')'); % Make it visible upon loading
savefig(fignew,'test.fig');
delete(fignew);
If there is a colorbar, you'll need to do some extra work (you have to copy that as well using COPYOBJ since it is not a child of the axes).
  댓글 수: 1
Daniel Green
Daniel Green 2017년 8월 10일
Thank you! Only needed the second part, but the whole block of code helps.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by