New to matlab, help?
Show older comments
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 Comment
Steven Lord
on 30 Oct 2019
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.
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!