E. Working With Programs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

E.

Working with Programs


1. If you want to solve problems which Matlab cannot do in one line, you will need to write programs. To
access the editor, you may choose any of the following:
a. Select File > New > M-file from Matlab desktop
b. Click the new file button on the desktop toolbar
c. Type edit then hit Enter in Command Window

2. Type the following into the Editor:

x = 0 : pi/20 : 6 * pi; <Enter>


plot(x, exp(-0.2*x) .*sin(x), ‘r’), grid <Enter>

3. Save the file in the current directory as sample.m in the current directory.

4. In Command Window, you may run the saved script file by typing:

>> sample <Enter>

Note: A script file may be listed in the Command Window with the command type, e.g.

>> type sample <Enter>

5. When you run a script, you have to make sure that Matlab’s current directory is set to the directory to
which the script is saved. To change directory, browse through the current directory or change from the
command line, e.g.

>> cd \mystuff <Enter>

F. Capturing output
1. To capture output in Command Window, type

>> diary filename <Enter>


>> diary off <Enter>

You might also like