I wish to open a saved figure in the figure number of my choice.

조회 수: 25 (최근 30일)
PRADEEP KUMAR VUTLA
PRADEEP KUMAR VUTLA 2019년 9월 8일
댓글: PRADEEP KUMAR VUTLA 2019년 9월 12일
I wish to open a saved figure in the figure number of my choice.
This saves a lot of effort while resuming a higher number of runs, helps in pausing the runs by saving the figures. It helps in recalling the saved figures and helps in resuming a lot of runs again.
Kindly help with this feature....

답변 (3개)

Cris LaPierre
Cris LaPierre 2019년 9월 8일
Basically, use the figure command and specify the number.
figure(5)
Just beware that, if that figure exists (is open), rather than create a new figure, it will make the existing figure active. Any commands you executes for creating the figure will act on the existing figure.

Adam Danz
Adam Danz 2019년 9월 8일
편집: Adam Danz 2019년 9월 8일
When you open a figure it takes the next available figure number and the figure number property is read-only and cannot be reassigned.
The analysis should not rely on a figure number. If specific figures need referenced, figure handles, names or tags should be used to identify the figure. (see name and tag properties in the link above).
For example
h = open('figure.fig') % now you can use 'h' no matter what the figure number is
% -or-
figure('tag','myUniqueTag')
h = findall(0,'type','figure','tag','myUniqueTag'); % now you've got the figure handle
% -or-
figure('name','myUniqueName')
h = findall(0,'type','figure','name','myUniqueName'); % now you've got the figure handle
One way to "change" the number of a figure you open is to start a new figure with the specified number (ie, figure(10)) and then use copyobj() to copy the opened figure to the new one. I don't recommend this because figure 10 may already exist and now it's destroyed. Also, it's extra work that can be avoided by following the advice above instead.
Another sloppy way to make sure your opened figure has number 'x' is to merely create x-1 empty figures. This is really ugly and bad but it's still a way to get there.
desiredFigNum = 10;
close all %start with 0 figures
fh = gobjects(1,desiredFigNum-1);
for i = 1:desiredFigNum-1
fh(i) = figure('visible','off'); % not visible
end
open('figure.fig')
delete(fh)

Bruno Luong
Bruno Luong 2019년 9월 8일
편집: Bruno Luong 2019년 9월 8일
clear
close all
fig=figure();
plot(rand(1,10));
hgsave(fig,'myfig.fig');
input('type <CR> to continue and see load file <myfig.fig> in figure 1000: ','s')
close all
fig = figure(1000);
src = openfig('myfig.fig','invisible');
copyobj(get(src,'Children'),fig)
% You might replicate other figure properties such as position, units, callback etc...
close(src);

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by