Using the selected string of listdlg not the index number

10 ビュー (過去 30 日間)
Tobias Welby
Tobias Welby 2017 年 3 月 17 日
回答済み: Guillaume 2017 年 3 月 17 日
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?

回答 (1 件)

Guillaume
Guillaume 2017 年 3 月 17 日
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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by