필터 지우기
필터 지우기

New to matlab, help?

조회 수: 2 (최근 30일)
Torbjørn Herland
Torbjørn Herland 2019년 10월 30일
댓글: Steven Lord 2019년 10월 30일
Hi, our class has startet learning matlab, but we just got some mandatory tasks and i barely know anything about the program yet. Although i do have almost a month to do it i really need helping hand in where to start. I'll copy in one of the tasks below:
Create a program that asks the user to enter a number using digits and stores the number in a variable. The program should respond "Thank you!" And quit if users enter a number. If the user enters something that is not a number, the program should notify the user and ask again. The program should continue to ask again until the user enters a number. It is not necessary for the program to recognize numbers written in letters. For example, the program must understand that the entry 50 is a number, but does not need to understand that the entry "fifty" is also a number.
A little help to get started would be wonderfull!
Hints for the task was tr2num and isempty.
  댓글 수: 1
Steven Lord
Steven Lord 2019년 10월 30일
Since you said you "barely know anything about the program yet", my first recommendation is to work through the free, roughly two hour long, MATLAB Onramp tutorial. The goal of this tutorial is to teach you the basics of working with MATLAB.
As for the hint you received, I'd be wary of using str2num. Instead I recommend str2double. str2num evaluates the text you pass into it, which would mean if your user entered the text 'exit' at your prompting MATLAB would exit because the exit function was called. str2double doesn't do that. You would have to use a slightly different function to detect the user entering something that's not a number, so I'll give an alternate hint: isnan instead of isempty.

댓글을 달려면 로그인하십시오.

채택된 답변

Thomas Satterly
Thomas Satterly 2019년 10월 30일
Since this is an assignment, I'm not going to just give you the code, but there are a few pages you should look at to get you on the right track.
First of all, I think you meant "str2num" instead of "tr2num". However, I'd recommend using str2double instead - it's usually preferred and less arbitrary.
Also, check out the input command. That's the easiest way to prompt for user data, but there's certiantly flashier options if you want a pop-up window or more robust input handling.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by