Programming |
M-File Functions
This section covers the following topics:
M-File Structure
An M-File consists of the components shown here:
function [x, y] = myfun(a, b, c) %Function definition line
%H1 line
-- A one-line summary of the function's purpose. %Help text
-- One or more lines of help text that explain % how to use the function. This text is displayed when % the user types "helpfunctionname
". % TheFunction body
normally starts after the first blank line. %Comments
-- Description (for internal use) of what the function % does, what inputs are expected, what outputs are generated. % Typing "helpfunctionname
" does not display this text. x = prod(a, b); % Start ofFunction code
For more information: See Basic Parts of an M-File of the MATLAB Programming documentation.
Using Lowercase for Function Names
Function names appear in uppercase in MATLAB help text only to make the help easier to read. In practice, however, it is usually best to use lowercase when calling functions.
For M-file functions, case requirements depend on the case sensitivity of the operating system you are using. As a rule, naming and calling functions using lowercase generally makes your M-files more portable from one operating system to another.
Getting a Function's Name and Path
To obtain the name of an M-file that is currently being executed, use the following function in your M-file code.
To include the path along with the M-file name, use
For more information: See the mfilename
function reference page.
What M-Files Does a Function Use?
For a simple display of all M-files referenced by a particular function, follow the steps below:
clear
functions
to clear all functions from memory (see Note below).
inmem
to display all M-Files that were used when the function ran. If you want to see what MEX-files were used as well, specify an additional output, as shown here:
Note
clear functions does not clear functions locked by mlock . If you have locked functions, (which you can check using inmem ), unlock them with munlock , and then repeat step 1.
|
Dependent Functions, Built-Ins, Classes
For a much more detailed display of dependent function information, use the depfun
function. In addition to M-files, depfun
shows which built-ins and classes a particular function depends on.
Development Environment | Function Arguments |
© 1994-2005 The MathWorks, Inc.