This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Interactive input of text

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


textinput(<prompt1>, x1, <prompt2>, x2, …)


textinput allows interactive input of text.

textinput() displays the prompt "Please enter text:" and waits for input by the user. The input is converted to a character string, which is returned as the function's return value.

textinput(prompt1) uses the character string prompt1 instead of the default prompt "Please enter text:".

textinput( prompt1 x1) converts the input to a character string and assigns this string to the identifier or local variable x1. The default prompt is used, if no prompt string is specified.

Several input values can be read with a single textinput command. Each identifier in the sequence of arguments makes textinput return a prompt, waiting for input to be assigned to the identifier or variable. A character string preceeding the identifier or variable in the argument sequence replaces the default prompt. Cf. Example 3. Arguments that are neither prompt strings nor identifiers or variables are ignored.

The input may extend over several lines. In the output string, MuPAD® uses the character \n (carriage return) to separate lines.

Input characters with a leading \ are not interpreted as control characters, but as two separate characters.

The identifiers or variables x1 etc. may have values. These are overwritten by textinput.


Example 1

The default prompt is displayed, the input is converted to a character string and returned:

Please enter text input: << myinput >> 

Example 2

A user-defined prompt is used, the input is assigned to the identifier x:

textinput("enter your name: ", x)
enter your name: << Turing >> 


delete x:

Example 3

If several values are to be read, separate prompts can be defined for each value:

textinput("She: ", hername, "He:  ", hisname)
She: << Bonnie >> He:  <<
Clyde >> 

hername, hisname

delete hername, hisname:


prompt1, prompt2, …

Input prompts: character strings

x1, x2, …

identifiers or local variables

Return Values

Last input, converted to a character string.

Was this topic helpful?