input — Prompt users for interactive input in MATLAB and RunMat.

input(prompt) displays prompt, reads one line from the user, and returns the evaluated value. Passing 's' as the second argument returns raw text instead of numeric evaluation, following MATLAB semantics.

Syntax

value = input()
value = input(prompt)
value = input(prompt, stringFlag)
value = input(stringFlag, prompt)

Inputs

NameTypeRequiredDefaultDescription
promptAnyYesPrompt text shown to the user.
stringFlagStringScalarYesSet to 's' to return the raw input text.

Returns

NameTypeDescription
valueAnyParsed scalar/matrix value, or raw text when using string mode.

Errors

IdentifierWhenMessage
RunMat:input:TooManyInputsMore than two input arguments are passed to input.input: too many inputs
RunMat:input:InvalidStringFlagThe string mode flag is not a scalar string/char 's'.input: invalid string flag
RunMat:input:PromptMustBeRowVectorPrompt char array is not 1-by-N.input: prompt must be a row vector

How input works

  • 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). In wasm hosts, prompts are delivered to the installed async input handler and execution continues after the handler resolves.
  • 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 backs str2double. This covers scalar numbers, MATLAB-style vector/matrix literals, Inf, NaN, and complex tokens. Arbitrary expressions (for example 1+rand()) are not evaluated automatically—read the text with 's' and pass it to eval once 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:InvalidNumericExpression so callers can present a friendly retry loop.

Example

value = input("Enter a scalar: ")

Using input with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how input changes the result.

Run a small input example, explain the result, then change one input and compare the output.

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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how input is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.