MATLAB: Matlab App Designer ListBox.Value changes when ItemsData is an array

appdesignerlistbox

Hi All,
I am having a problem with app designer LisxtBox. I have a ListBox and I define the names of my items in a cell array (for example; ch1, ch2, ch3, ch4). When I use the following commands, I can retrieve the selected item or its index
app.ListBox.Value
[~,index] = ismember(app.ListBox.Value,app.ListBox.Items)
However, when I attribute (match) the items with an array (for example; ch1 becomes Nx1, N being the number of data points. I use app.ListBox.ItemsData for defining each items data array), automatically 'app.ListBox.Value' becomes 'Nx1' cell array.
My intention is only be able to retrive the name of the item I selected (when I click on listbox item, I only want to see ch1, ch2 etc., not Nx1 array). Should I use something else rather than 'ListBox.Value'? Can you please help me with that?
Thank you.

Best Answer

I think what you're looking for is,
[~,index] = ismember(app.ListBox.Value, app.ListBox.ItemsData); % Note: ItemsData
% This returns a character vector; it won't work with >1 selection
value = app.ListBox.Items{index};
% This returns a cell containing char-vectors
value = app.ListBox.Items(index);