Reputation: 41
Is there any possible way to open the desired figures from a lot of plotted figures in MATLAB?
If it is possible with dialogue box then it will be perfect.
I have like 75 figures plotted after my code but I have closed the figures at end of loops as they are too much.
Is it possible to open just one figure by just entering values necessary for plotting figure in MATLAB at end of program?
Upvotes: 3
Views: 263
Reputation: 2575
From Wikibooks: MATLAB Programming/Handle Graphics (emphasis mine):
Every time you close a figure, either by using the close function OR by hitting the 'X', you can no longer access the data, and attempts to do so will result in an error. Closing a figure also destroys all the handles to the axes and annotations that depended on it.
This means that once you close your 75 figures, they are gone for good.
I would suggest saving all your figures to .fig
file format, because this will allow you to open them later in MATLAB.
Take the following example:
x = linspace(0, 2*pi); % Sample data.
for i = 1:3 % Loop 3 times.
h = figure; % Create figure window and capture its handle.
plot(i*sin(x)); % Plot some data.
saveas(h, sprintf('fig%d.fig', i)); % Save figure to .fig file format.
close(h); % Delete the figure.
end
Now you can tell MATLAB to open one of the figures using the openfig
function. For example, let's open the second figure fig2.fig
. Go to the Command Window and type openfig('fig2')
(including the .fig
extension in the file name is optional).
>> openfig('fig2')
ans =
Figure (1) with properties:
Number: 1
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [520 371 560 420]
Units: 'pixels'
Show all properties
Upvotes: 1
Reputation: 276
One way to do this is the following:
1) You save the figures as .fig
in a dedicated folder using the saveas
command, e.g.:
saveas(gcf,['FileName_',num2str(idx),'.fig']);
where idx
is the index associated with the figure number (so in 75 in the example you mentioned). For simplicity, I would save all of them in one folder.
2) You use inputdlg
to create an input dialog box, where you type in the index you want. Then, you run uiopen(['FileName_',idxFromInput,'.fig'])
, which will display the figure. Note that the output from inputdlg
is normally a string, so you don't need num2str
here.
Upvotes: 2