When using listdlg to create a menu, how do you access the user input?

I'm writing a script which gives the user 10 coundries of which they must pick 2. I'm using listdlg for the menu, but how do I view/display their choices?
This is what I've got so far...
cList = {'United Kingdom','Bulgaria','Germany','Greece','Sweden','Netherlands','Spain','Romania','Luxembourg','Poland'};
[indx,tf] = listdlg('PromptString','Select 2 countries to study','ListString',cList);
the variable indx gives the number of the countries selected (eg UK=1,Bulgaria=2...), and cList is a 1x10 cell
Thanks in advance.

 採用された回答

dpb
dpb 2020 年 12 月 17 日

0 投票

>> cList = {'United Kingdom','Bulgaria','Germany','Greece','Sweden','Netherlands','Spain','Romania','Luxembourg','Poland'};
[indx,tf] = listdlg('PromptString','Select 2 countries to study','ListString',cList);
>> indx
indx =
4 9
>> cList(indx)
ans =
1×2 cell array
{'Greece'} {'Luxembourg'}
>>
You just use the indices return to index into the list.
However, you can't control how many the user actually selects; it's either 'Single' or 'MultiSelect' on input and you only know how many the user selected when he returns.
You'll have to write code to test the size of the return array and decide how to handle the cases when user doesn't follow instructions.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

2020 年 12 月 17 日

コメント済み:

2020 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by