How to get subplots made of a group of already existing .fig
6 views (last 30 days)
Show older comments
Good morning, I have a problem with creating a subplots figure that must have as figures already existing plots. What I do is to save the plots as .fig figures, then what i want to do is not to plot the figure singularly, but to plot them smaller and one next to the other in a 4x2 subplot figure.
I'm not using plot() in a loop for subplotting since each figure has its linear regression equation printed on plot through sprintf, so I'd prefer to save each figure before putting it in the subplot.
Also, i'd like subplots to stay closer, so I tried with "tight_subplots", but I'm in trouble with how to plot existing figures.
Thank you so much for your attention!
I'm currently trying with this, but it doesn't work:
%after having defined in previous lines hf(1)= figure(1) etc.. before the "plot()" sentence
hf(9) = figure(9)
ha(1) = subplot(4,2,1);
ha(2) = subplot(4,2,2);
ha(3) = subplot(4,2,3);
ha(4) = subplot(4,2,4);
ha(5) = subplot(4,2,5);
ha(6) = subplot(4,2,6);
ha(7) = subplot(4,2,7);
ha(8) = subplot(4,2,8);
for i = 1:8
hc = get(hf(i),'children')
hgc = get(hc, 'children');
set(hgc, 'parent',ha(i));
end
And i get this error:
Error using matlab.ui.Figure/get
Invalid or deleted object.
Error in microctd_turb_20apr (line 653)
hc = get(hf(i),'children')
1 Comment
Bruno Luong
on 3 Aug 2023
The issue seems to arise from earlier part of your code or user interaction with figure hf(i) but you didn't post it.
Answers (1)
Bruno Luong
on 3 Aug 2023
Edited: Bruno Luong
on 3 Aug 2023
It seems to work for me
% I invent this part
for fig = 1:8
hf(fig) = figure(fig);
plot(sin(linspace(1,fig)));
set(hf(fig), 'Visible', 'off'); % not necessary needed, I just don't to display here a blucnh of blank figure
end
% This is your code
hf(9) = figure(9);
ha(1) = subplot(4,2,1);
ha(2) = subplot(4,2,2);
ha(3) = subplot(4,2,3);
ha(4) = subplot(4,2,4);
ha(5) = subplot(4,2,5);
ha(6) = subplot(4,2,6);
ha(7) = subplot(4,2,7);
ha(8) = subplot(4,2,8);
for i = 1:8
hc = get(hf(i),'children'); % by all mean just do not CLOSE the figure hf(i)
hgc = get(hc, 'children');
set(hgc, 'parent',ha(i));
end
2 Comments
Bruno Luong
on 3 Aug 2023
More questions unrelated to THIS question. Please post new question if you didn't find what you are looking for.
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!