Advanced MATLAB Commands and Functions
Other Useful Functions and Commands
Listed below are a few of the many MATLAB commands/functions. Use the help command for more detailed information on the commands and functions.
| help | Prints list of all the topics for help |
| demo | Runs demonstrations: list the topics for which demos are available |
| whos | Lists variables in memory |
| what | Lists the M-files, MAT-files and MEX-files in the current working directory |
| size | Provides row and column dimensions: returns the size of the predefined matrix if it is given a proper argument |
| length | Shows vector length |
| clear | Clears workspace, all variables get cleared from the memory |
| save | Saves the contents of workspace into mat file |
| load | Loads the content of an already saved mat file |
| diary | Creates a log of all the inputs and outputs generated into a an ASCII file |
External Interface
MATLAB interacts with data and program external to it. It provides an Application Program Interface (API) to support these external interfaces. The functions supported by API include:
- Calling C or Fortran programs from within MATLAB
- Importing and exporting data to and from MATLAB environment.
MEX-files
These are dynamically linked subroutines provided from C or Fortran source code. While they behave just like M-files and other builtin functions, Mex-files are not platform independent and they have to have a platform- specific extensions.
C and Fortran MEX-files
The include (header files) are located at: /usr/usc/matlab/default/extern/include. Some examples of MEX-files are located at: /usr/usc/matlab/default/extern/examples/mex
Compiling and linking
To compile and link the source files written in C, at the MATLAB prompt, type the command mex. This will create a mexsol file, which will behave exactly like an M-file in MATLAB. You can also combine several object and use libraries while building MEX-file. The full path name for the mex function is: /usr/usc/matlab/default/bin/mex.
Important header files and libraries
| mex.h | MEX-file declaration and prototype | |
| mat.h | Mat-file declaration and prototype | |
| engine.h | engine declaration and prototype | |
| matrix.h | basic matrix access methods | |
| libmex | library for building MEX-files | |
| libmat.a | library for MAT-files and engine routines |
Notes:
- mex.h, mat.h, engine.h all include matrix.h themselves, so there is no need to include matrix.h explicitly.
- mex.h, mat.h, engine.h all include matrix.h themselves, so there is no need to include matrix.h explicitly.
Basic Plotting and Graphic Functions
| plot | Graph of vectors with linear scales for both axes |
| loglog | Graph with logarithmic scale for both axes |
| semilogx | Graph with logarithmic scale for x-axis and a linear scale for y-axis |
| semilogy | Graph with logarithmic scale for y-axis and a linear scale for x-axis |
| plotyy | Graph with y-tick labels on the left and right side |
| title | Title of the graph |
| xlabel | Label of the x-axis |
| ylabel | Label of the y-axis |
| gtext | Place text on the graph using the mouse |
| text | Display text on specific location |
| grid | Turn the grid on |
3-D Graphics
| mesh,surf | Surface plot for matrix data |
| meshc,surfc | Surface plot with contour plot beneath it |
| meshz | Surface plot with reference plane |
| pcolor | Flat surface plot (value is proportional only to color) |
| surfl | Surface plot illuminated from specified direction |
| surface | Low-level function (on which high-level functions are based) |
| plot3 | The 3-D analog of the plot function |
Getting Help With MATLAB
To get general MATLAB help, type help at the MATLAB command prompt to get a list of a help topics. To get help on a specific topic or function, type help
MathWorks provides extensive MATLAB documentation online. To access this documentation, go to MATLAB Getting Started
If you have questions regarding this documentation, or are having trouble logging into your account and sourcing the MATLAB setup files, please contact the Customer Support Center at 213-740-5555 or email consult@usc.edu.
Last updated:
February 07, 2011