Interactive mode is the simplest way to use MATLAB. In this mode, the user types commands at the MATLAB prompt (>>) and gets immediate results. MATLAB keeps track of the list of variables which have been created, their types, and values, and the special variable ans which is always set to the result of the most recent operation. The history of commands which have been issued to the interpreter is available via the up arrow key and in the Command History window to allow the user to easily access recently-called functions or variable assignments.


>> disp 'Hello World';

Hello World

In this example, we make use of the built-in MATLAB function disp, which takes a string (in MATLAB a string is any group of characters between single quotes), vector, or array and prints it to the screen (interpreter window). Other slightly more advanced functions are available for printing to the screen (sprintf) and to a file (fprintf). Their syntax is similar to the C functions with the same names. Finally, the semicolon character is used to suppress output printing in MATLAB. MATLAB normally echos the result of any function call back to the interpreter window, but it will not do this if you have a semicolon following the command.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement