23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

This is the first line of text that appears when a user types help functionname<br />

at the <strong>MATLAB</strong> prompt. Further, the lookfor function searches on and<br />

displays only the H1 line. Because this line provides important summary<br />

information about the M-file, it is important to make it as descriptive as<br />

possible.<br />

Help Text<br />

You can create online help for your M-files by entering help text on one or<br />

more consecutive comment lines at the start of your M-file program. <strong>MATLAB</strong><br />

considers the first group of consecutive lines immediately following the H1<br />

line that begin with % to be the online help text for the function. The first line<br />

without % as the left-most character ends the help.<br />

The help text for the average function is<br />

% AVERAGE(X), where X is a vector, is the mean of vector<br />

% elements. Nonvector input results in an error.<br />

When you type help functionname at the command prompt, <strong>MATLAB</strong><br />

displays the H1 line followed by the online help text for that function. The<br />

help system ignores any comment lines that appear after this help block.<br />

Note Help text in an M-file can be viewed at the <strong>MATLAB</strong> command prompt<br />

only (using help functionname). You cannot display this text using the<br />

<strong>MATLAB</strong> Help browser. You can, however, use the Help browser to get help<br />

on <strong>MATLAB</strong> functions and also to read the documentation on any MathWorks<br />

products.<br />

The Function or Script Body<br />

The function body contains all the <strong>MATLAB</strong> code that performs computations<br />

and assigns values to output arguments. The statements in the function body<br />

can consist of function calls, programming constructs like flow control and<br />

interactive input/output, calculations, assignments, comments, and blank<br />

lines.<br />

For example, the body of the average function contains a number of simple<br />

programming statements:<br />

4-12

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

Saved successfully!

Ooh no, something went wrong!