필터 지우기
필터 지우기

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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by