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일
>> 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 Exchange에서 Entering 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