matlab_test, a MATLAB code which illustrates various features of MATLAB.


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


matlab_test is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and codes:

matlab_calls_c, MATLAB codes which call a C function using the MEX facility.

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

matlab_os, MATLAB codes which invoke an operating system command.

matlab_random_test, MATLAB codes which illustrate the use of Matlab's random number generators.

Source Code:

boolean_print_test shows how to print booleans as 'True' or 'False'.

character_to_string_test shows how to convert between MATLAB's character vector and string data types using convertCharsToStrings() and convertStringsToChars();

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

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

files_test shows how MATLAB can check whether a directory exists, and create it or remove it.

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

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

integer_print_test looks at how to print an integer array so that all the digits show up, without a scaling factor.

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

RAND_TEST looks at how rand() generates uniform random values.

RANDN_TEST looks at how randn() generates normal random values.

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

spacing_test 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.

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.)

Last revised on 28 October 2020.