Creating Buttons Tabs and Panels from Input Number

4 Ansichten (letzte 30 Tage)
McLain Cowan
McLain Cowan am 17 Mär. 2021
Kommentiert: McLain Cowan am 29 Jun. 2021
Here is an example of my Code that keeps returning the error " 'Parent' must be a parent component, such as a uifigure object. This is all done in Designer.
___________________________________________________________________________________________________________________________
X= 3
app.UIFigure = uifigure;
app.TabGroup = uitabgroup(app.UIFigure)
for i=1:X
app.Tab(i) = uitab(app.TabGroup)
app.Panel(i) = uipanel(app.Tab(i))
app.Button(i) = uibutton(app.Panel(i))
end
_____________________________________________________________________________________________________________________________
Once it gets to app.Button the error occurs. Lets say X = 3, I do get 3 Tabs and 3 Panels (1 in each Tab) but it is unable to create the 1 Button in each Panel.
Thanks

Antworten (1)

Reshma Nerella
Reshma Nerella am 18 Jun. 2021
Hi,
You can do it this way.
  1. Create a private property allComps, use it as a structure to hold arrays for tabs, panels and buttons
  2. Create an EditField for the input number
Use the below code for creating tabs,panels and buttons.
app.allComps.tabG = uitabgroup(app.UIFigure);
for i = 1:app.EditField.Value
app.allComps.tabs(i) = uitab(app.allComps.tabG,'Title', "tab"+i);
app.allComps.panels(i) = uipanel(app.allComps.tabs(i));
app.allComps.buttons(i) = uibutton(app.allComps.panels(i),'Text',"button"+i);
end
Hope this helps!
  1 Kommentar
McLain Cowan
McLain Cowan am 29 Jun. 2021
This does not work... This is what I am trying to do currently. I am trying to put buttons onto multiple tabs:

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop uifigure-Based Apps 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!

Translated by