How can I generate selected number of tabs in tab group with app designer?
조회 수: 11 (최근 30일)
이전 댓글 표시
I need to generate selected number of tabs within one tab group using app designer. Is there any way to do it?
I tried to make the same as from the answer https://www.mathworks.com/matlabcentral/answers/229411-gui-with-changeable-number-of-tabs
My code:
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [300 300 300 300];
tab = uitab(app.TabGroup,'Title','Main Tab'); %create the main tab
for x = 1:5 %create the number of tabs entered by the user
tab.(['t' num2str(x)]) = uitab(app.TabGroup,'Title',['Tab' num2str(x)]);
end
But there is only one generated tab (figure below) and error "Unrecognized property 't1' for class 'matlab.ui.container.Tab'."

What can I do? Thanks.
댓글 수: 0
채택된 답변
Adam Danz
2020년 3월 20일
편집: Adam Danz
2020년 3월 20일
You're treating tab like a structure but it's a tab container object. Store the tab handles in a cell array. Here's a demo you can adapt to your app.
% Create a UI Figure
app.UIFigure = uifigure();
% Set up tab group
app.TabGroup = uitabgroup(app.UIFigure);
% app.TabGroup.Position = [300 300 300 300]; % not needed for demo
% Specify the total number of tabs
nTabs = 6; % including MainTab
% Set up the main tab
app.tabs = cell(1,nTabs);
app.tabs{1} = uitab(app.TabGroup,'Title','Main Tab'); %create the main tab
% Create additional tabs
for i = 2:nTabs %create the number of tabs entered by the user
app.tabs{i} = uitab(app.TabGroup,'Title',['Tab' num2str(i-1)]);
end
To access tab number 'n',
app.tabs{n}
app.tabs{n}.Title = 'Menu'; % for example
Note: when applying this to AppDesigner you'll need to declare tabs as a private property by following these instructions.
댓글 수: 7
Will Reeves
2022년 8월 19일
편집: Will Reeves
2022년 8월 19일
Actually... is it just OK to "copy" the "handle" to a local variable and delete it? It seems to work - as in the tab disappears from the GUI, but is it "clean"?
for i=1:length(app.tabs)
a=app.tabs{i};
delete(a);
end
Adam Danz
2022년 9월 16일
@Will Reeves sorry for the delay, I was out on vacation for a while.
> is it just OK to "copy" the "handle" to a local variable and delete it
Yes. When you copy a variable containing a handle to another variable, you are making a semantic copy. Both variables are referencing the same object and if you make changes to properties using one variable, those properties will correctly be represented in the second variable.
For a deeper dive, see this blog post:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Create Custom UI Components에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!