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 />

Working with M-Files<br />

<strong>MATLAB</strong> provides a full programming language that enables you to write a<br />

series of <strong>MATLAB</strong> statements into a file and then execute them with a single<br />

command. You write your program in an ordinary text file, giving the file<br />

anameoffilename.m. Thetermyouusefor filename becomes the new<br />

command that <strong>MATLAB</strong> associates with the program. The file extension<br />

of .m makesthisa<strong>MATLAB</strong>M-file.<br />

This section covers<br />

• “Types of M-Files” on page 4-8<br />

• “Basic Parts of an M-File” on page 4-9<br />

• “Creating a Simple M-File” on page 4-13<br />

• “ProvidingHelpforYourProgram”onpage4-16<br />

• “Creating P-Code Files” on page 4-16<br />

TypesofM-Files<br />

M-files can be scripts that simply execute a series of <strong>MATLAB</strong> statements, or<br />

they can be functions that also accept input arguments and produce output.<br />

<strong>MATLAB</strong> scripts:<br />

• Are useful for automating a series of steps you need to perform many times.<br />

• Do not accept input arguments or return output arguments.<br />

• Store variables in a workspace that is shared with other scripts and with<br />

the <strong>MATLAB</strong> command line interface.<br />

<strong>MATLAB</strong> functions:<br />

• Are useful for extending the <strong>MATLAB</strong> language for your application.<br />

• Can accept input arguments and return output arguments.<br />

• Store variables in a workspace internal to the function.<br />

4-8

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

Saved successfully!

Ooh no, something went wrong!