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

6 次查看(过去 30 天)
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

采纳的回答

Gayatri Menon
Gayatri Menon 2018-2-12
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by