How to use questdlg to ask the user for an action?
6 ビュー (過去 30 日間)
古いコメントを表示
I want to ask the user to make a choice on which function to excute
the algorithm is as follows:
- Ask the user "what type of selection?"
- possible answers a) random b)roulette-wheel 3)tournment
- if the answer is random selection, excute the random.m file
- if the answer is roulette-wheel , excute the roulette-wheel.m file
- if the answer is tournment, excute the tournment.m file
Not sure how to do it
i tried this but caught me in an infinite loop.
%x,y,z are defined in the actual code
answer = questdlg('choose a selection method?', ...
'selection methods', ...
'random','roulette-wheel','tournment');
% Handle response
switch answer
case 'random'
selch=random(x,y,z)
case 'roulette-wheel'
selch=roulette-wheel(x,y,z)
case 'tournment'
selch=tournment(x,y,z);
end
0 件のコメント
回答 (1 件)
John D'Errico
2019 年 10 月 20 日
編集済み: John D'Errico
2019 年 10 月 20 日
Your first problem is you are not using it correctly.
The last argument should be one of the choices, to give it a default button selection.
answer = questdlg('choose a selection method?', ...
'selection methods', ...
'random','roulette_wheel','tournment','random');
(You spelled tournament incorrectly, not that it matters.)
But the above will give you a dialog box with three options, one of which (the first) is highlighted.
How it caught you in an infinite loop is difficult to know, since we lack your other code. Perhaps something in your code calls itself recursively, although if it did, then you would get a stack limit exceeded error, not a true infinite loop, because it will crash long before things go near infinite.
Another error in the code is you cannot name a function roulette-wheel. You CAN name it roulette_wheel, which is what I put in the call to questdlg. A minus sign cannot be part of a function name, but an underscore can be.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dialog Boxes についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!