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

indxlistlistdlgmenu

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 1×10 cell
Thanks in advance.

Best Answer

>> 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.
Related Question