02.03.2016 Views

MATLAB by rudra pratap

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1. 7 Visit This Again<br />

13<br />

1. 7 Visit This Again<br />

We would like to point out a few things that vex the <strong>MATLAB</strong> beginners , perhaps,<br />

the most. Although many of these things would prohably not make sense to you<br />

right now, they are here, and you can come back to them whenever they seem<br />

relevant.<br />

In the past, file navigation in <strong>MATLAB</strong> has caused considerable problems for<br />

users, especially the beginners. We have had numerous complaints from students<br />

about not being able to make <strong>MATLAB</strong> find their file, get <strong>MATLAB</strong> to work from<br />

their directory, get <strong>MATLAB</strong> to find and exec.ute the currently edited file, etc.<br />

Fortunately, from <strong>MATLAB</strong> 6 onward, Math Works has incorporated several new<br />

features that mitigate this problem immensely. The current directory is shown just<br />

above the command window with the option of changing it with just a click of the<br />

mouse. There is also a current directory subwindow to the left of the command<br />

window that lists files in the current directory and gives you options of opening,<br />

loading (Mat-file) , executing (M-file) , editing, etc., with the click of the right button<br />

on the mouse. You can also change the directory there or add a particular directory<br />

to the <strong>MATLAB</strong> path so that <strong>MATLAB</strong> has access to all the files in that directory<br />

automatically.<br />

If you do not save all your <strong>MATLAB</strong> files in the default Work directory or folder,<br />

you need to be aware of the following issues.<br />

1. Not being in the right directory: You may write and save many <strong>MATLAB</strong><br />

programs (M-files) but <strong>MATLAB</strong> does not seem to find them. If your files<br />

are not in the current working directory, <strong>MATLAB</strong> cannot access them. Find<br />

which directory you are currently in <strong>by</strong> looking at the small current directory<br />

window in the toolbar or <strong>by</strong> querying <strong>MATLAB</strong> with the command pwd. If<br />

you are not in the right place, guide <strong>MATLAB</strong> to get to the directory where<br />

your files are. See Lesson 10 in the tutorials (Chapter 2).<br />

2. Not saving files in the correct directory: When you edit a file in the<br />

<strong>MATLAB</strong> editor/debugger window and save it, it does not automatically<br />

mean that the <strong>MATLAB</strong> command window has access to the directory you<br />

saved your file in. So, after saving the file, when you try to execute it and<br />

MAT LAB does not find your file, follow item 1 above and set things right.<br />

3. Not overwriting an existing file while editing: You run your program <strong>by</strong><br />

executing your M-file, do not like the result, edit the file, and run it again;<br />

but <strong>MATLAB</strong> gives the same answer! The previou;;ly parsed (compiled) file<br />

is executing; <strong>MATLAB</strong> does not know about your changes. This can happen<br />

due to various reasons. The simple cure is, clear the workspace with clear<br />

all and execute your file.<br />

There are various other little things that cause trouble from time to time. We<br />

point them out throughout the book wherever they raise issues.

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

Saved successfully!

Ooh no, something went wrong!