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

조회 수: 8 (최근 30일)
Serena Sirigu
Serena Sirigu 2018년 1월 29일
답변: Gayatri Menon 2018년 2월 12일
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