0

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?

1
  • 1
    Have you checked the input function? That might be what you want. Type help input to see how it works Commented Oct 24, 2013 at 22:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.