How can I generate selected number of tabs in tab group with app designer?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mikhail Mikhail
el 20 de Mzo. de 2020
Comentada: Adam Danz
el 16 de Sept. de 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 comentarios
Respuesta aceptada
Adam Danz
el 20 de Mzo. de 2020
Editada: Adam Danz
el 20 de Mzo. de 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 comentarios
Will Reeves
el 19 de Ag. de 2022
Editada: Will Reeves
el 19 de Ag. de 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
el 16 de Sept. de 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:
Más respuestas (0)
Ver también
Categorías
Más información sobre Create Custom UI Components en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!