How to get subplots made of a group of already existing .fig
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Bruno Luong
le 3 Août 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.
Réponses (1)
Bruno Luong
le 3 Août 2023
Modifié(e) : Bruno Luong
le 3 Août 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 commentaires
Bruno Luong
le 3 Août 2023
More questions unrelated to THIS question. Please post new question if you didn't find what you are looking for.
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!