Programming and Data Types |
What's in an M-File?
This section shows you the basic parts of a function M-file, so you can familiarize yourself with MATLAB programming and get started with some examples.
function f = fact(n) % Function definition line % FACT Factorial. % H1 line % FACT(N) returns the factorial of N, H! % Help text % usually denoted by N! % Put simply, FACT(N) is PROD(1:N). f = prod(1:n); % Function body
This function has some elements that are common to all MATLAB functions:
lookfor
or request help on an entire directory.
Refer to Functions for more detail on the parts of a MATLAB function.
Kinds of M-Files | Providing Help for Your Programs |