Using the C++ Math Library    

Input and Output

MATLAB supports several functions for input and output. The simplest one is disp(), short for display. Pass disp() an array, and the array appears on the terminal screen. For example:

Here, 'Hello World' is a string array.

One group of I/O functions in MATLAB are like their namesakes in the C programming language. MATLAB supports fprintf(), sprintf(), scanf(), and sscanf(). fprintf() prints to files, sprintf() to strings, while scanf() and sscanf() read from files and strings, respectively. The arguments to these functions can be simple or complex. For example:

This call creates this string array:

Notice how the sprintf() command recycled its format string argument through the four elements of its data argument.

The I/O functions load() and save() allow you to save array variables from your application to what's called a MAT-file. That data can then be loaded back in by your application or by another application.

See Example - Using load() and save() (ex7.cpp) and Example - Using File I/O Functions (ex6.cpp) in Chapter 8 for more details on MATLAB input and output.


 Functions Errors