How do I list out all of the repetitive rows depending on the number of variables in MATLAB App Designer?

14 views (last 30 days)
I would like to make these row repetitive based on variables that I have. If let's say user input 10 items, there will be 10 rows. Is it possible to do this? The reason why I didn't use the UI.Table is because users are able to choose different item (in dropdown menu) based on preferences.
This would be similar as picture below. Taken a snapshot from another matlab tutorial.

Answers (1)

Sreeram
Sreeram on 28 Oct 2024 at 9:06
Hi Nurhidayah,
Yes, it is possible to add UI components to the app’s UI Figure based on a variable.
For example, if you want several UI Dropdowns equal to ‘numRows’, one below the other, you add the following code snippet to an appropriate place, such as the button-clicked callback of an Update button. Note that if you want to use variables like ‘dd1’ in another function, consider setting them as Private Properties.
for rowNum=1:numRows
dd1(rowNum) = uidropdown(app.UIFigure, ...
'Position', [10, 40 * (numRows - rowNum + 1), 100, 30], ... % adjust as needed
'Items', {'Option 1', 'Option 2', 'Option 3'}, ...
'Tag', 'Option 1');
% add the other components in appropriate positions
end
You can refer to the documentation on how to add the components programmatically here:
If the added components extend beyond the app’s UI Figure and you want to add them to a scrollable container, consider adding them to a “Panel” instead of the app's UI Figure and setting the setting the “Scrollable” property to ‘on’. More details are available in the documentation for “Panel”:
I hope this helps!

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!