Matlab’s App Designer’s listbox lacks some of functionality of GUIDE’s listbox.
App Designer’s listbox currently offers no direct method to obtain the index number of a selected item.
Here is a roundabout method for a sample listbox named listbox_type:
Items = char(app.listbox_type.Items);
im=app.listbox_type.Value;
[n]=find_index(Items,im)
% n is the index of the selected item
function[n]=find_index(Items,im)
im=strtrim(im);
n=1;
sz=size(Items);
for i=1:sz(1)
sss=strtrim(Items(i,:));
if(strcmp(im,sss))
n=i;
break;
end
There is probably a more streamline way of doing this though.
Update. Here is a better way from: https://chat.openai.com/
Items = strtrim(app.ListBox.Items);
im = strtrim(app.ListBox.Value);
n = find(strcmp(Items, im))
– Tom Irvine