Plot alternatively between uitab of two figures
조회 수: 5 (최근 30일)
이전 댓글 표시
I want two figures, where each figure has several tabs, and I want to plot tab per tab alternatively between the two figures (i.e. tab1 of fig1, tab1 of fig2, tab2 of fig1, tab2 of fig2, tab3 of fig1, tab3 of fig2, ...
Below is my current code, which is not working. In the first figure I get tabs with one white plot only, and in the second figure I get the expected plot of the first figure in the first tabs, and I get the correct plot in the last tab.
I don't understand why, since the axes seem correctly related to the tab, the tab correctly related to the tabgroup, and the tabgroup correctly related to the figure. Something escapes me.
fig_1 = figure("name", "Fig 1");
fig_2 = figure("name", "Fig 2");
tabgroup_1 = uitabgroup(fig_1);
tabgroup_2 = uitabgroup(fig_2);
for idx_t = 1:3
tab_1 = uitab(tabgroup_1, "Title", "Fig 1, tab " + num2str(idx_t));
axes("Parent", tab_1);
subplot(2,1,1); plot(1:10);
subplot(2,1,2); plot((1:10).^idx_t);
tab_2 = uitab(tabgroup_2, "Title", "Fig 2, tab " + num2str(idx_t));
axes("Parent", tab_2);
subplot(2,1,1); plot(1:10);
subplot(2,1,2); plot(-(1:10).^idx_t);
end
댓글 수: 0
채택된 답변
Robert U
2022년 8월 24일
Hi Jérôme,
most problems occure when not using handles. Your subplot command does not adress the correct figure. I introduced temporary handles to show how it could be done:
fig_1 = figure("name", "Fig 1");
fig_2 = figure("name", "Fig 2");
tabgroup_1 = uitabgroup(fig_1);
tabgroup_2 = uitabgroup(fig_2);
for idx_t = 1:3
tab_1 = uitab(tabgroup_1, "Title", "Fig 1, tab " + num2str(idx_t));
tmp_sh = subplot(2,1,1,'Parent',tab_1); plot(tmp_sh,1:10);
tmp_sh = subplot(2,1,2,'Parent',tab_1); plot(tmp_sh,(1:10).^idx_t);
tab_2 = uitab(tabgroup_2, "Title", "Fig 2, tab " + num2str(idx_t));
tmp_sh = subplot(2,1,1,'Parent',tab_2); plot(tmp_sh,1:10);
tmp_sh = subplot(2,1,2,'Parent',tab_2); plot(tmp_sh,-(1:10).^idx_t);
end
Kind regards,
Robert
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!