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.

 Réponse acceptée

Jan
Jan le 26 Avr 2019
Modifié(e) : Jan le 26 Avr 2019
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.

Plus de réponses (0)

Catégories

En savoir plus sur Entering Commands dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by