How to get subplots made of a group of already existing .fig
조회 수: 11 (최근 30일)
이전 댓글 표시
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
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
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
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 Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!