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

25 visualizaciones (últimos 30 días)
PRADEEP KUMAR VUTLA
PRADEEP KUMAR VUTLA el 8 de Sept. de 2019
Comentada: PRADEEP KUMAR VUTLA el 12 de Sept. de 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....

Respuestas (3)

Cris LaPierre
Cris LaPierre el 8 de Sept. de 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.

Adam Danz
Adam Danz el 8 de Sept. de 2019
Editada: Adam Danz el 8 de Sept. de 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)

Bruno Luong
Bruno Luong el 8 de Sept. de 2019
Editada: Bruno Luong el 8 de Sept. de 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);

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by