This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 14:440:127– Introduction to Computers for Engineers Notes for Lecture 9- Exam 2 Review Rutgers University, Fall 2009 Instructor- Blase E. Ur 1 Review- Plotting 1.1 X-Y Line Plots • Key Idea 1: plot(X,Y) expects X and Y to be vectors of x points and y points. These vectors should be the same size. X and Y are just variable names. • Key Idea 2: You could just as well do plot([1 2 3], [100 200 300]) , which plots the points (1,100), (2,200), and (3,300), connecting them with a line. • Key Idea 3: You can often use the colon or linspace operators to create the vector of x points. • Key Idea 4: When calculating the y points, say if your equation is y = x 2 , remember to use the dot operator: y = x.^2 since x is a vector of points, and you want to square each individual point . • Key Idea 5: After calling plot , you can call functions like title( ) , xlabel( ) , and ylabel( ) to title the graph, label the x axis, and label the y axis, respectively. Each of these functions takes a single string of characters as its input. • Key Idea 6: axis[xmin xmax ymin ymax]) changes the graph’s axes. • Key Idea 7: Use the ginput function to insist that the user click somewhere on a graph. You normally call the function by typing something like [x y] = ginput(3) , which specifies that you want two outputs (vectors of the x and y coordinates of the points they clicked), and that you’re insisting they click 3 points before the program continues. 1.2 Plotting Multiple Things • Key Idea 1: If you want to open different windows for different graphs, call the function figure(X) to refer to window number X. If that window already exists, you’ll now be able to overwrite the currently existing graph. If it doesn’t exist already, Matlab will open a blank window and be ready for you to plot something in that window. • Key Idea 2: If you want to plot multiple graphs on the same set of axes in the same window, your first method is to just call plot(x1,y1,x2,y2,...) . Note that you always give x points, then the corresponding y points, then the next set of x points, then the corresponding y points, and so on. You can call legend(’name1’,’name2’,...) to create a legend. However many sets of x-y vectors you have, that’s how many strings (separated by commas) you send to the legend function. • Key Idea 3: If you want to plot multiple graphs on the same set of axes, and it’s not simple to use a single plot command (i.e. you’re plotting a histogram on top of a pie chart, for whatever reason), type hold on after plotting the first graph. From then until you type hold off , you’ll be displaying everything on top of each other in the same window. Legends are more tricky to display using this method....
View Full Document
- Fall '09
- loop, Rutgers University