Azzera filtri
Azzera filtri

How to use questdlg to ask the user for an action?

12 visualizzazioni (ultimi 30 giorni)
I want to ask the user to make a choice on which function to excute
the algorithm is as follows:
  1. Ask the user "what type of selection?"
  2. possible answers a) random b)roulette-wheel 3)tournment
  3. if the answer is random selection, excute the random.m file
  4. if the answer is roulette-wheel , excute the roulette-wheel.m file
  5. 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', ...
% Handle response
switch answer
case 'random'
case 'roulette-wheel'
case 'tournment'

Risposte (1)

John D'Errico
John D'Errico il 20 Ott 2019
Modificato: John D'Errico il 20 Ott 2019
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', ...
(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.


Scopri di più su Dialog Boxes in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by