input — Prompt the user for input. Return either the typed text or a parsed numeric value.
input(prompt) displays prompt, waits for the user to type a line of text, and then returns the evaluated value. When you pass 's' as the second argument, input skips numeric parsing and returns the raw text as a character row vector. RunMat mirrors MATLAB’s single-line prompt/response flow so scripts that rely on interactive questions continue to work.
How input works in RunMat
- Prompts accept character row vectors and string scalars. When omitted, RunMat uses
"Input: ". - The function always blocks until the host supplies a line of text (via the REPL, CLI pipe, or wasm bindings).
stdinRequestedevents surface the outstanding prompt to JS hosts so they can resume later. - When
's'(or"s") is provided, the return value is a character array containing exactly what the user typed (without the trailing newline). - Without
's', RunMat forwards the response through the same numeric parser that backsstr2double. This covers scalar numbers, MATLAB-style vector/matrix literals,Inf,NaN, and complex tokens. Arbitrary expressions (for example1+rand()) are not evaluated automatically—read the text with's'and pass it toevalonce that builtin lands. - Empty responses (just pressing Enter) return an empty
[]double, consistent with MATLAB. - When the numeric parser rejects the text, RunMat raises
RunMat:input:InvalidNumericExpressionso callers can present a friendly retry loop.
Example
value = input("Enter a scalar: ")FAQ
Does RunMat evaluate arbitrary MATLAB expressions?
Not yet. The numeric branch reuses the str2double parser, which supports MATLAB numeric literals (scalars, vectors, matrices, Inf, NaN, complex pairs) but does not run arbitrary code. When you need to evaluate expressions such as 1+sin(pi/4), capture the text via input(..., 's') and pass it to eval in a follow-up release.
What happens if the user just presses Enter?
RunMat returns the empty double [], matching MATLAB’s input behaviour.
Can I call input inside GPU workloads?
Yes. Prompts always flow through the host console/UI. GPU-resident prompt arguments are gathered once before display, and the response itself is always a host value.
What does input do in MATLAB?
input(prompt) displays the prompt string and waits for the user to type a response. The response is evaluated as a MATLAB expression. Use input(prompt, 's') to return the raw text as a string without evaluation.
How do I get string input from the user in MATLAB?
Use str = input('Enter text: ', 's'). The 's' flag tells MATLAB to return the typed text as a character vector instead of evaluating it as an expression.
What is the difference between input and keyboard in MATLAB?
input pauses for a single value from the user and returns it, while keyboard drops into an interactive debugging session. RunMat supports input for scripted user interaction.
Can I validate user input in MATLAB?
Use a while loop: keep calling input until the value passes your validation check. For example, while x < 0; x = input('Enter positive number: '); end.
Does input work in RunMat's browser sandbox?
Yes. input prompts the user within the RunMat sandbox. In non-interactive contexts, it returns the default empty value.
Related functions to explore
These functions work well alongside input. Each page has runnable examples you can try in the browser.
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how input works, line by line, in Rust.
- View input.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.