How i can create a list box items in matlab app designer?

8 views (last 30 days)
Hello! I am trying to create my first app with matlab designer. I created a field where type a vector elements and i would like to have for example:if my vector size is 3, automatically the number of items in my list box are 3 named:Sample1, Sample2, Sample3... Is there a way to do this? Thanks

Accepted Answer

Gayatri Menon
Gayatri Menon on 12 Feb 2018
Hi, You can do this by manipulating the Callback functions of the "EditFeild". The following link might help you in giving you an overview on writing callbacks in App designer
Inside the callback, you can create a cell array which contains all possible values you want to display in the Listbox. Then you can use the length of the vector which is inputted through the "Editfeild" to choose a subset of the cell array and then manipulate the “Items” property of the "Listbox" accordingly. For example:
The following code snippet can be inserted in the “ValueChanged” Callback function of the Editfeild, so that when user enters the vectors as comma separated list and Press Enter, the Listbox Items changes according to the size of vector
value = app.VectorEditField.Value; % Vector is the name of the Editbox
value_Converted=str2double(strsplit(value,',')); %Convert string which is the default datatype for Editfeild(text) to double
value_size=length(value_Converted) % get the vector size
Total_Items={'Sample1','Sample2','Sample3'};
app.SamplesListBox.Items=Total_Items(1:value_size)% Samples is the name of listbox
Hope the above helps Thanks

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!