# Plot alternatively between uitab of two figures

조회 수: 13 (최근 30일)
Jérôme . 2022년 8월 23일
댓글: Jérôme . 2022년 8월 24일
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 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 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.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

R2021a

### Community Treasure Hunt

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

Start Hunting!