MATLAB Answers

How to have a multiple choice questionnaire that will ask the next question depending on the answer?

46 ビュー (過去 30 日間)
AbdullahMZ
AbdullahMZ 2019 年 10 月 17 日
回答済み: Jos (10584) 2019 年 10 月 17 日
Hi everyone,
I am trying to have a multiple-choice questionnairequestionnaire, that will go to the next step (in this case, the next question) depending on what you answer.
What is the best approach for this? I was thinking of using an if-else statement; however, I don't know how to have a multiple choice question.
I really hope you guys can help me with this!
Thank you

  3 件のコメント

Rik
Rik 2019 年 10 月 17 日
Do you want to use a GUI, or do you want a linear program that uses only the command window?
AbdullahMZ
AbdullahMZ 2019 年 10 月 17 日
whichever one is better, I have never used GUI, but if it's better then I don't mind using it.
Rik
Rik 2019 年 10 月 17 日
Neither is intrinsically better than the other. For a 'normal' function you should probably use functions like menu or listdlg. It depends on how complicated your question tree is how complicated your code will get.

サインインしてコメントする。

回答 (1 件)

Jos (10584)
Jos (10584) 2019 年 10 月 17 日
Take a look at all the dialog functions in matlab like questdlg, listdlg etc.
Start however drawing a graph of all the questions and the paths to the next questions depening on the answers. In your code you can use if-else-end or, even better, switch-case-end constructs
answer = questdlg(...)
switch answer
case 'A' % ask follow-up 1
case 'B' % ask follow-up 2
otherwise
end

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by