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!