I'm building an app in MatLab's App designer and I need the number of some UI Elements to be variable, depending on the user's input. I want to create an array of these objects (which are of the same type/class), so that I can cycle through them, accessing and changing their properties.
This is an example of the callback function that is called when the user confirms his input by pressing a button:
layerNum = app.layersFld.Value;
gridHeight = 2+layerNum;
gridWidth = 6+layerNum;
configGrid = uigridlayout(app.ConfigPanel, [gridHeight, gridWidth]);
for i=1:gridHeight
dd(1,i) = uidropdown(configGrid);
dd(1,i).Layout.Row = i;
dd(1,i).Layout.Column = i;
end
A notification tells me "The variable 'dd' appears to change size on every loop iteration. Consider preallocating for speed.". How would I go about doing this? I tried differenct array classes/constructors but I get error codes everytime. Is there a constructor for arrays containing UI elements/objects?
BTW: This code snippet works as is, the app runs as expected and checking the outcome of the for-loop in a seperate m-file showed me that a horizontal vector with dropdown elements in each position is created... But I'd like to learn doing it the right way, optimizing my app and learn more about how MatLab handles objects.