How to Edit Drop Down Item field based on a changing variable in App Designer

Hi
If I have a variable that is changing depending on the users interaction with the App, how am I able to code the items section of the dropdown menu to incorporate said variable.
for example
if c = 'hay';'bye' (2x3 char array)
i can write app.DropDown.Items = {c(1,:), c(2,:)} which gives me the items i want in the drop down field.
However I want to automate it so the app.dropdown.items field is populated by the variable c which might not be (2x3) but for a different case be (9x3) so Id like 9 items in the drop down. How would I go about doing that.
This is an extremely simple version of what I am trying to do but just want to understand what sort of code/function would work. any help is appreciated.

 Accepted Answer

This is not clear, because it is no valid Matlab code:
if c = 'hay';'bye' (2x3 char array)
Do you mean: c = ['hay', 'bye']?
Working with char matrices is a bad idea, because the padding with zeros is not convenient. What about using strings or cell strings?
c = {'hay', 'bye'}
% or
c = ["hay", "bye"]
In both cases, this works easily:
app.DropDown.Items = c
This uses all elements of c directly without the need to know the number of elements in advance.

More Answers (0)

Categories

Asked:

on 26 Apr 2019

Commented:

on 26 Apr 2019

Community Treasure Hunt

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

Start Hunting!