MATLAB Answers

0

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

Asked by PRADEEP KUMAR VUTLA on 8 Sep 2019
Latest activity Commented on by PRADEEP KUMAR VUTLA on 12 Sep 2019
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....

  0 Comments

Sign in to comment.

3 Answers

Answer by Cris LaPierre
on 8 Sep 2019

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.

  0 Comments

Sign in to comment.


Answer by Adam Danz
on 8 Sep 2019
Edited by Adam Danz
on 8 Sep 2019

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)

  0 Comments

Sign in to comment.


Answer by Bruno Luong
on 8 Sep 2019
Edited by Bruno Luong
on 8 Sep 2019

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);

  1 Comment

Excellent! It's working well.
Thank you...

Sign in to comment.