A small problem on my homework assignment has something to do with case expression.

Here is the full question
Suppose that a student has the option of enrolling for a single elective during a term. The student must select a course from a limited list of options: “English,” “History,” “Biology,” “Computer,” or “Math.” Construct a fragment of MATLAB code that will prompt the student for his or her choice, read in the choice, and use the answer as the case expression for a switch construct. Be sure to include a default case to handle invalid inputs. Testing three cases: (a) Computer (b) Physics (c) Biology.
Now the problem is the first part i dont understand the "Construct a fragment of MATLAB code that will prompt the student for his or her choice, read in the choice," part. I know how to do the case expression part.
I dont want you guys to do the problem for me just guide me. Plz Love you all <3

 採用された回答

Image Analyst
Image Analyst 2014 年 10 月 30 日
Did you happen to find menu() in the help? Try this:
button = menu('Select a class', '(a) Computer', ' (b) Physics', '(c) Biology');
switch button
.... more code.....

4 件のコメント

Hasan
Hasan 2014 年 10 月 30 日
isn't that the same thing as case expression?
menu gives you the number of the button they clicked on, which will be 1, 2, or 3 for these 3 items. You said you knew how to use switch/case statements so I assume you know that after the switch line will be a case line. You can also have "otherwise" and it must finish with an end, as you know.
switch button
case 1
% Code to do it button is 1
etc.
You should know because you said "I know how to do the case expression part." so I shouldn't have to tell you. If menu works for you, please mark the Answer as Accepted. By the way, you can also use questdlg() or inputdlg() or (cough, gag) input(), but the menu() function is by far the easiest way in this situation.
Hasan
Hasan 2014 年 10 月 30 日
Thanks, im new the matlab so im a newb. Thanks for the help and ill let you know if it works xD. is it okay if i show you the code so that you can confirm it?
Image Analyst
Image Analyst 2014 年 10 月 31 日
Sure. Go ahead and post it.

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

その他の回答 (1 件)

Ken Atwell
Ken Atwell 2014 年 10 月 30 日

0 投票

I like Image Analyst's suggestion because a multiple-choice UI eliminate the need to check for bad input, but your professor might be looking for the input function, used to gather textual input in the Command Window.
Have fun.

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

質問済み:

2014 年 10 月 30 日

コメント済み:

2014 年 10 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by