Noura Aldossari
Noura Aldossari

Reputation: 1

How to get input from user in function

I want to ask about function M-file in MATLAB: if I want input from the user, how do I do that?

Can I write the input directly in the function M-file?

Or do I have to write an input statement in a script file and return to the function file to write another statement?

Upvotes: 0

Views: 345

Answers (1)

cxw
cxw

Reputation: 17041

As Luis mentioned, the input function (documentation) prompts the user and then receives input. As far as I know, it will work fine whether in a function or in a script. If you find that it doesn't, post the code so folks can take a look at it.

input will treat what the user types as if you had typed it at a matlab command line. For example, if your code says

count=input('Enter a count')

and the user enters 3*5, the value of count will be 15. To get exactly "3*5", use input('Prompt','s') instead.

Upvotes: 2

Related Questions