Plot alternatively between uitab of two figures

7 次查看(过去 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

采纳的回答

Robert U
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
  1 个评论
Jérôme
Jérôme 2022-8-24
Thank you, this solves the problem.
I also tried to give the "Parent" to the subplot function, which was not solving the issue, but I did not think about giving what it returns to the plot function.
For me since the plot function was directly following the subplot function, and that the subplot was correctly parented, it was ok. I still don't understand why it's not the case, but at least I know how to make it works.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by