|Programming and Data Types|
Obtaining User Input
There are three ways to obtain input from a user during M-file execution. You can:
This section covers the first two topics. The third topic is discussed in online documentation under Creating Graphical User Interfaces.
Prompting for Keyboard Input
input function displays a prompt and waits for a user response. Its syntax is
The function displays the
prompt_string, waits for keyboard input, and then returns the value from the keyboard. If the user inputs an expression, the function evaluates it and returns its value. This function is useful for implementing menu-driven applications.
input can also return user input as a string, rather than a numeric value. To obtain string input, append
's' to the function's argument list.
Pausing During Execution
Some M-files benefit from pauses between execution steps. For example, the
petals.m script, shown in the "Simple Script Example" section, pauses between the plots it creates, allowing the user to display a plot for as long as desired and then press a key to move to the next plot.
pause command, with no arguments, stops execution until the user presses a key. To pause for
n seconds, use
|Calling Functions||Subscripting and Indexing|