MATLAB is a numerical computing environment and programming language. Created by The MathWorks, MATLAB allows easy matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. Many classes in our ECEn Department requires professional skill using matlab, such as ECEn 360, ECEn 370, ECEn 380, ECEn 483...This tutorial is for those who never touch matlab before or need some review for matlab.
P.S. Matrix operations are very similar to the array operations, detailed information can be found in the attached document.
After setting and operating on arrays, the best way to see the behavior of x and y, or x,y, and z is to graph them. The most common functions for graphing are; plot, stem, polar, subplot, mesh, meshc, surf, surfc , and hold on.
Some times we need to see the behavior of three variables. In EcEn 360, it's required to plot a 3D graph of the probability with two variables. There are many useful functions that can simulate 3D graphs depending on which one you need.
This function is mainly used for parametric functions, the syntax is: plot3(X1,Y1,Z1,...) where X1, Y1, Z1 are vectors or matrices. It will plot one or more lines in three-dimensional space through the points whose coordinates are the elements of X1, Y1, and Z1.
The syntax for these two functions is very similar to plot3, both are: mesh/surf(x,y,z). The difference is that these two functions will output a surface graph instead of only the connections of the dots.
if mech is replaced by surf, then the result will be:
P.S. In this program, [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y.
These two functions will give you the idea of a 3D graph in a 2D one. "meshc" function will give you the contour plot of a 3D graph. "view(2)" will give you the view of a 3D graph when looking down from the top of it.
Y = diff(X,n) applies diff recursively n times, resulting in the nth difference. For example, diff(X,2) is the same as diff(diff(X)). So for the first example above, if you type: z = diff(x,2) The result will be "z = 0 0 0"
Integrals work similar to derivatives. Matlab can also approximate implement integrals. There are many functions that can do this, such as: cumsum, trapz, quad, etc. The cumsum function is the most useful one.
The syntax is: B = cumsum(A). It returns the cumulative sum along different dimensions of an array. If A is a vector, cumsum(A) returns a vector containing the cumulative sum of the elements of A. If A is a matrix, cumsum(A) returns a matrix the same size as A containing the cumulative sums for each column of A.
X=cos(n^2)*sin(2*pi*n/5)*u(t) and h=((0.9)^n)*(u(t)-u(t-10))
Then the code will be:
The result is:
Filter and sampling processing will be taught in detail in ECEn380 class, you can also check it in the attached document.
Help and look for function
The Help function is the most useful function in Matlab. It lists all primary help topics in the Command Window. Each main help topic corresponds to a directory name on the MATLAB search path.
The Syntax of help function is:
This command lists all operators and special characters, along with their descriptions.
This command displays M-file help, which is a brief description and the syntax for functionname, in the Command Window. The output includes a link to doc functionname, which displays the reference page in the Help browser, often providing additional information. I think that doc link is the most useful link in Matlab. It should contains all you want to know.
A very convenient tool of MATLab 7.0 for graphing
If you don't like coding and still want to see the behavior of a function or two functions, the easiest way to do that in MatLab 7.0 is using the "funtool" function.