How can I generate selected number of tabs in tab group with app designer?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mikhail Mikhail
am 20 Mär. 2020
Kommentiert: Adam Danz
am 16 Sep. 2022
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 Kommentare
Akzeptierte Antwort
Adam Danz
am 20 Mär. 2020
Bearbeitet: Adam Danz
am 20 Mär. 2020
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 Kommentare
Will Reeves
am 19 Aug. 2022
Bearbeitet: Will Reeves
am 19 Aug. 2022
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
am 16 Sep. 2022
@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:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Create Custom UI Components finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!