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.

3 Basic Program Components<br />

<strong>MATLAB</strong> Functions<br />

Many of the functions provided with <strong>MATLAB</strong> are implemented as M-files<br />

just like the M-files that you will create with <strong>MATLAB</strong>. Other <strong>MATLAB</strong><br />

functions are precompiled executable programs called built-ins that run much<br />

more efficiently.<br />

This section discusses both types of functions and also functions that are<br />

overloaded to handle different data types appropriately:<br />

• “M-File Functions” on page 3-110<br />

• “Built-In Functions” on page 3-111<br />

• “Overloaded <strong>MATLAB</strong> Functions” on page 3-112<br />

M-File Functions<br />

If you look in the subdirectories of the toolbox\matlab directory, you can find<br />

theM-filesourcestomanyofthefunctionssuppliedwith<strong>MATLAB</strong>.Youcan<br />

locate your toolbox\matlab directory by typing<br />

dir([matlabroot '\toolbox\matlab\'])<br />

<strong>MATLAB</strong> functions with an M-file source are just like any other functions<br />

coded with <strong>MATLAB</strong>. When one of these M-file functions is called, <strong>MATLAB</strong><br />

parses and executes each line of code in the M-file. It saves the parsed version<br />

of the function in memory, eliminating parsing time on any further calls to<br />

this function.<br />

Identifying M-File Functions<br />

To find out if a function is implementedwithanM-file,usetheexist function.<br />

The exist function searches for the name you enter on the <strong>MATLAB</strong> path and<br />

returns a number identifying the source. If the source is an M-file, then exist<br />

returns the number 2. This example identifies the source for the repmat<br />

function as an M-file:<br />

exist repmat<br />

ans =<br />

2<br />

3-110

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

Saved successfully!

Ooh no, something went wrong!