フィルターのクリア

How to get subplots made of a group of already existing .fig

11 ビュー (過去 30 日間)
Francesca Pisani
Francesca Pisani 2023 年 8 月 3 日
コメント済み: Bruno Luong 2023 年 8 月 3 日
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 件のコメント
Bruno Luong
Bruno Luong 2023 年 8 月 3 日
The issue seems to arise from earlier part of your code or user interaction with figure hf(i) but you didn't post it.

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2023 年 8 月 3 日
編集済み: Bruno Luong 2023 年 8 月 3 日
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 件のコメント
Francesca Pisani
Francesca Pisani 2023 年 8 月 3 日
Thank you, i think the problem was that since my code is very long I was just running the last section but figures were plotted in the previous ones.
I have one some more questions:
  • how can I do to add names to axes (each one has different names for me)
  • how can I assign also a name to each subplot like (a), (b), (c), etc. written below each horizontal axis
thank you so much for helping me
Bruno Luong
Bruno Luong 2023 年 8 月 3 日
More questions unrelated to THIS question. Please post new question if you didn't find what you are looking for.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by