MATLAB Examples

**MATLAB**
is a directory of MATLAB programs which
illustrate the use of the MATLAB interactive programming environment.

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Directories related to **MATLAB** are available in
a C version and
a C++ version and
a FORTRAN77 version and
a FORTRAN90 version and
a MATLAB version and
a Python version.

F90_MATLAB, MATLAB functions which are called by a FORTRAN90 program.

MATLAB_C, MATLAB programs which call a C function using the MEX facility.

MATLAB_COMMANDLINE, MATLAB programs which illustrate how MATLAB can be run from the UNIX command line, that is, not with the usual MATLAB command window.

MATLAB_F77, MATLAB programs which call a FORTRAN77 function using the MEX facility.

MATLAB_MOVIES, MATLAB programs which generate animations.

MATLAB_OS, MATLAB programs which invoke an operating system command.

MATLAB_RANDOM, MATLAB programs which illustrate the use of Matlab's random number generators.

**CPU_TIMING** shows how you can measure the CPU time required for
a given computation.

- cpu_timing.m, the program.
- cpu_timing_output.txt, the output file.

**FACTORIAL** uses the standard example of the factorial function
to demonstrate MATLAB's ability to implement a recursive function.

- factorial.m, the program.

**GLOBAL_VARIABLES** shows how two functions can communicate
the value of a variable, without using the argument list, by declaring
the variable with a GLOBAL statement.

- global_variables.m, the program.

**HELLO** is a simple example to print out "Hello, world!".

- hello.m, the program.
- hello_output.txt, the output file.

**HELLO_ITHACA_QUEUE** shows how the "Hello" program can be run
on the Ithaca cluster.

- hello.m, the program.
- hello_ithaca_queue.sh, an NQS file that can be submitted to the Ithaca queue by the command "qsub hello_ithaca_queue.sh".
- hello_ithaca_queue_output.txt, the output file.

**PERSIST** shows how a persistent variable can be used to "remember"
the value of some variable within a function between calls.

- persist.m, the program.
- persist_output.txt, the output file.

**RECURSIVE_TEST** shows how you can use recursion in a function
definition.

- recursive_test.m, the source code;
- recursive_test_output.txt, the output file;

**SPACING_MATTERS** demonstrates that MATLAB can fail to interpret
an arithmetic statement correctly because of the occurrence of a blank space.
This occurs when creating a vector by listing entries. MATLAB allows
the lazy practice of not separating entries by commas, and the result
can be an error that is very hard to interpret.

- spacing_matters.m, the program.

**STARTUP** is a MATLAB script that can be used to initialize
MATLAB. You have to know where to put it, though. (Hint: start MATLAB,
and type "pwd" to find out where MATLAB starts by default. That's
where you want to put this file.)

- startup.m, a simple startup file that moves MATLAB's current directory to a place that suits me better.

You can go up one level to the MATLAB source codes.