input
Prompts the user for a value or text at the command window.
Category: Programming > Scripts
Syntax
x = input(prompt)
Shows prompt, evaluates what the user types as an expression and returns the result.
txt = input(prompt, 's')
Returns the typed characters as text, without evaluating them.
Description
input stops the script and waits for a line of keyboard input. In the default form the line is evaluated as MATLAB code, so typing 2*pi returns 6.2832. With 's' the line is returned untouched as a character vector, which is the safe choice for names and free text.
Because it blocks until someone answers, input suits interactive sessions rather than programs that must run unattended.
Input arguments
prompt- Text shown before the cursor.
's'- Option that returns the raw text instead of evaluating it.
Output arguments
x- The value of the typed expression, or the typed text when
's'is used.
Example
Calling input without a console
try
x = input('Value: ');
catch err
disp(err.message)
end
input is not supported: MatLivre runs scripts without an interactive command window.
MatLivre has no interactive command window, so the call fails with a message that this snippet prints.
Notes
MatLivre runs scripts without an interactive command window, so input raises an error instead of waiting. Pass values through variables or function arguments instead.