EE 350 – Linear Systems I MATLAB Tutorial #1 The homework assignments in this course contain problems that must be completed using MATLAB. A minimal knowledge of MATLAB is required to get started. Advanced MATLAB features will be introduced in tutorials posted on the homework web page. Students who have not used MATLAB before should go to the following web page: http://www.mathworks.com/academia/student_center/tutorials/launchpad.html View the “Getting Started” and “MATLAB Examples” videos for an overview. Then proceed to the Interactive MATLAB Tutorials and view “Navigating the MATLAB Desktop” and “MATLAB Fundamentals.” This will give you enough information to proceed with the remainder of this tutorial. Basic Graphs It is simple to produce graphs with MATLAB. In the online tutorial information above you have learned to create a simple function. As shown, we can produce one cycle of a sine wave with the following MATLAB code: >> x=0:0.01:2*pi; >> y=sin(x); The sine function will be plotted with the plot command: >> plot(x,y) resulting in the graph below: From the Insert Menu in the Figure window experiment with adding an x and y axis label along with a title for the graph. If you are running version 7.8 or MATLAB, use the plottools command to modify the graph. Or, view the “Visualizing Data” tutorial on the Interactive Tutorial page. subplot Command In the example above, the plot command was used to produce a graph. The figure window shows a single 2D plot. When a new plot command is issued that plot is overwritten by the new graph. The command, subplot is used to display multiple graphs in the same figure window. The command: subplot(m, n, p) breaks the figure window into an m x n matrix of small axes and selects the p-th pair of axes for the next plot. Try: >> >> >> >> >> >> >> >> >> >> >> >> >> t = 0:.01:2; x = t.^2; y = sqrt(t); z = t.^3; w = t.^2 + 2*t+1; subplot(2,2,1) plot(t,x) subplot(2,2,2) plot(t,y) subplot(2,2,3) plot(t,z) subplot(2,2,4) plot(t,w) Relational Operators MATLAB has six relational operators that make comparisons between arrays. These relational operators are shown in the table below. Relational Operator Meaning < Less than <= Less than or equal to > Greater than >= Greater than or equal to == Equal to ~= Not equal to The result of a comparison using a relational operator is either 0 (if the comparison is false), or 1 (if the comparison is true). For example, try the following set of commands: >> >> >> >> >> x y x x x = 5 = 2 > y < y == y % should return a one % should return a zero % should return a zero If we want to assign the returned value of the comparison to a variable we can use: >> u = (x==y) % the parenthesis are not required The relational operators can also be used to compare elements of a matrix or a vector. For example, try: >> >> >> >> x z w v = = = = [ 5 2 -1]; (x > y) (x < y) (x == y) y = [2 3 -1]; Creating Unit Step Functions Using the relational operators we have a simple method for creating a unit step function. Try: >> >> >> t = -1:.001:3; x = (t >=2); plot (t,x) Verify that this command creates a unit step function. A combination of these step functions can be used to create pulses. For example: >> t = -2:.001:2; >> x=(t>=-1) - (t>=1); >> plot(t,x) plots a pulse from -1 to 1 as shown below. The unit step function can also be used to create functions such as: ⎧ cos 2π t 0≤t≤1 ⎪ x(t) = ⎨ cos 4π t 1≤t≤2 ⎪ 0 elsewhere ⎩ This can be plotted using: >> t=-1:.001:3; >> x=cos(2*pi*t).*((t>=0)-(t>=1))+cos(4*pi*t).*((t>=1)-(t>=2)); >> plot(t,x)
© Copyright 2026 Paperzz