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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MATLAB Lecture 2 1. Introduction Today we create 2-dimensional and 3-dimensional plots. Once again, you should create a new directory for todays 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 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....
View Full Document

This note was uploaded on 04/19/2011 for the course MATH 21126 taught by Professor Johnson during the Spring '11 term at Carnegie Mellon.

Page1 / 8

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online