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.

12 <strong>Programming</strong> Tips<br />

Finding the <strong>MATLAB</strong> Root Directory<br />

The matlabroot function returns the location of the <strong>MATLAB</strong> installation<br />

on your system. Use matlabroot to create a path to <strong>MATLAB</strong> and toolbox<br />

directories that does not depend on a specific platform or <strong>MATLAB</strong> version.<br />

The following example uses matlabroot with fullfile to return a<br />

platform-independent path to the general toolbox directory:<br />

fullfile(matlabroot,'toolbox','matlab','general')<br />

Temporary Directories and Filenames<br />

If you need to locate the directory on your system that has been designated to<br />

hold temporary files, use the tempdir function. tempdir returns a string that<br />

specifies the path to this directory.<br />

To create a new file in this directory, use the tempname function. tempname<br />

returns a string thatspecifiesthepathtothetemporaryfiledirectory,plusa<br />

unique filename.<br />

For example, to store some data in a temporary file, you might issue the<br />

following command first.<br />

fid = fopen(tempname, 'w');<br />

12-54

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

Saved successfully!

Ooh no, something went wrong!