# Lecture2 - MATLAB Lecture 2 1 Introduction Today we create...

This preview shows pages 1–3. Sign up to view the full content.

MATLAB Lecture 2 1. Introduction Today we create 2-dimensional and 3-dimensional plots. Once again, you should create a new directory for today’s exercises. 2. 2-D Graphics 2.1. The Plot Command. We have already seen the plot command, which is the most common command for plotting 2-dimensional data. This command plots sets of data arrays, connecting the points with straight lines. Example 2.1. x=linspace(0,2*pi,30); y=sin(x); plot(x,y) This example creates 30 data points 0 x 2 π which are used as the horizontal axis of the plot. Next we create a vector y containing the sine of the data points in x . The plot command opens a graphics window, scales the axes to fit the data, and then connect adjacent ponts with a straight line. It also adds a numerical scale and tick marks to both axes automatically. We can easily plot two data sets at once: z=cos(x); plot(x,y,x,z) 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This example draws both sin(x) and cos(x) versus x on the same plot. Note that plot automatically draws the second curve using a different color. Additional curves may be plotted by supplying additional pairs of arguments to plot. If one of the arguments is a matrix and the other is a vector, then the plot command plots each row of the matrix versus the vector. W=[y;z] % note that you must use ; to make this a matrix plot(x,W) title(’plot(x,W)’) 2.2. Linestyles, Markers and Colors.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern