Using the selected string of listdlg not the index number

10 views (last 30 days)
Hi,
I'm currently trying to find a way to use the string selected when using listdlg, not the index number it provides through the selection output.
So for example:
I somebody selects 'cat,' which is the third option in the list - instead of just getting the value 3, is there anyway to have it output the 'string' cat?
I am wanting the output of that selection to be used in a function, so just having the index value doesn't help.
Does anybody know a way to do this?

Answers (1)

Guillaume
Guillaume on 17 Mar 2017
Well, since you obviously have the ListString you passed to listdlg in the first place, just use the returned index to retrieve the selected value(s) from that list:
somelist = {'cat', 'dog', 'fish'};
[selectionindex, ok] = listdlg('ListString', somelist);
if ok
selectedvalues = somelist(selectionindex);
%do something with selectedvalues
end

Community Treasure Hunt

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

Start Hunting!