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.

Working with M-Files<br />

Once you have created this file, here are some things you can:<br />

• List the names of the files in your current directory:<br />

what<br />

• List the contents of M-file fact.m:<br />

type fact<br />

• Call the fact function:<br />

fact(5)<br />

ans =<br />

120<br />

A Word of Caution on Saving M-Files<br />

Save any M-files you create and any MathWorks supplied M-files that you<br />

edit in directories outside of the directory tree in which the <strong>MATLAB</strong> software<br />

is installed. If you keep your files in any of the installed directories, your files<br />

may be overwritten when you install a new version of <strong>MATLAB</strong>.<br />

<strong>MATLAB</strong> installs its software into directories under matlabroot/toolbox. To<br />

see what matlabroot is on your system, type matlabroot at the <strong>MATLAB</strong><br />

command prompt.<br />

Also note that locations of files in the matlabroot/toolbox directory tree are<br />

loaded and cached in memory at the beginning of each <strong>MATLAB</strong> session to<br />

improve performance. If you save files to matlabroot/toolbox directories<br />

using an external editor, or if you add or remove files from these directories<br />

using file system operations, enter the commands clear functionname and<br />

rehash toolbox before you use the files in the current session.<br />

For more information, see the rehash function reference page or the section<br />

Toolbox Path Caching in the Desktop Tools and Development Environment<br />

documentation.<br />

4-15

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

Saved successfully!

Ooh no, something went wrong!