How to define row and column of element in grid layout while initializing

8 views (last 30 days)
Purely for consolidating. I am creating an extensive UI within a script and it is getting slightly unwieldy having to (1) define grid layout element, (2) specify row, (3) specify column for any element that is not just a 1x1 that is going in the next space.
To illustrate, one of the first examples in this page has an element they define the row and column of:
% Range drop-down
dd2 = uidropdown(g);
dd2.Items = {'Select a range'};
dd2.Layout.Row = 2;
dd2.Layout.Column = 1;
Can I make this something like this to save space:
dd2 = uidropdown(g,'Items',{'Select a range'},'Layout.Row',2,'Layout.Column',1)
I have tried this and it doesn't work. If this is not possible, what is the point of the 'Layout' option it has in suggestions when creating an element (see screenshot)?

Accepted Answer

Rik on 12 May 2023
Edited: Rik on 12 May 2023
The point you're missing is that the Layout argument is expected to be a struct. Since Layout.Row is not a valid Matlab field name, the syntax you suggested doesn't work.
However, this should work:
dd2 = uidropdown(g,'Items',{'Select a range'},'Layout', struct('Row',2,'Column',1));

More Answers (0)


Find more on Shifting and Sorting Matrices 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!