23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4 M-File <strong>Programming</strong><br />

Function Definition Line<br />

The function definition line informs <strong>MATLAB</strong> that the M-file contains a<br />

function, and specifies the argument calling sequence of the function. The<br />

function definition line for the fact function is<br />

All <strong>MATLAB</strong> functions have a function definition line that follows this<br />

pattern.<br />

Function Name. Function names must begin with a letter, may contain any<br />

alphanumeric characters or underscores, and must be no longer than the<br />

maximum allowed length (returned by the function namelengthmax). Because<br />

variables must obey similar rules, you can use the isvarname function to<br />

check whether a function name is valid:<br />

isvarname myfun<br />

Although function names can be of any length, <strong>MATLAB</strong> uses only the first<br />

N characters of the name (where N is the number returned by the function<br />

namelengthmax) and ignores the rest. Hence, it is important to make each<br />

function name unique in the first N characters:<br />

N = namelengthmax<br />

N =<br />

63<br />

Note Some operating systems may restrict file names to shorter lengths.<br />

The name of the text file that contains a <strong>MATLAB</strong> function consists of the<br />

function name with the extension .m appended. For example,<br />

average.m<br />

4-10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!