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

5 views (last 30 days)
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.

Accepted Answer

dpb
dpb on 17 Dec 2020
>> 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.

More Answers (0)

Categories

Find more on Kernel Creation from MATLAB Code in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!