Plot alternatively between uitab of two figures

11 Ansichten (letzte 30 Tage)
Jérôme
Jérôme am 23 Aug. 2022
Kommentiert: Jérôme am 24 Aug. 2022
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

Akzeptierte Antwort

Robert U
Robert U am 24 Aug. 2022
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 Kommentar
Jérôme
Jérôme am 24 Aug. 2022
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by