This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Matlab M-Files There are four ways of doing code in Matlab . One can directly enter code in a terminal window. This amounts to using Matlab as a kind of calculator, and it is good for simple, low-level work. The second method is to create a script M-file. Here, one makes a file with the same code one would enter in a terminal window. When the file is “run”, the script is carried out. The third method is the function M-file. This method actually creates a function, with inputs and outputs. The fourth method will not be discussed here. It is a way to incorporate C code or FORTRAN code into Matlab ; this method uses .mex files. We will not disucss it here. 1 Terminal Input One can type the code in the Matlab terminal window. For example, if we wish to plot x sin(3 x 2 ) e- x 2 / 4 in the range [- ⇡ , ⇡ ], we could type the following in the terminal window. x =(-pi):pi/40:pi; ENTER y=x.*sin(3*x.ˆ2).*exp(-x.ˆ2/4); ENTER plot(x,y) ENTER The code listed above creates the row vector x , and then uses it to form a row vector y whose entries are the values of the function x sin(3 x 2 ) e- x 2 / 4 for each entry in...
View Full Document
This note was uploaded on 10/06/2011 for the course PGE 310 taught by Professor Klaus during the Spring '06 term at University of Texas at Austin.
- Spring '06