Flash and JavaScript are required for this feature.
Download the video from iTunes U or the Internet Archive.
Description: This video lecture demonstrates how to manipulate the style, axes, and position of plots in MATLAB and how to create multiple subplots.
Instructor: Yossi Farjoun
Lecture 4: Plotting
[? YOSSI FARJOUN: ?] This is [? Doctor ?] MATLAB, Lecture 4, Plotting. MATLAB is a great tool for making plots. You can plot your data. You can plot your results. You can make very elaborate plots. But first, we need to learn how to make simple plots.
So let's start with a simple plot. Let's plot sine on several points between 0 and 2 pi. So here we go, I've made the points. I put x versus sine of x. I'm going to dock this figure.
Great, so here is x versus sine x. I can do x versus cosine x. I can always also plot sine x versus cosine x. So the x is the sine, and the y is the cosine. And there it is.
It's supposed to be a circle. It looks like an ellipse, but notice it goes from minus 1 to 1, and from minus 1 to 1. So if you want to make it look like a circle, you can issue the command axis square. That looks like a circle.
But what if you wan it to be red circle? Then you can add the line style, r. You still have to tell it it to be square.
You can put more than one command, more than one plot on one figure. So you can do the following, hold, so now it's going to be held. Hold toggles it. If you hold again, it will be off. So I'm going to hold, or you can say hold on, and that will definitely be on.
And now, I want to plot, not x, but I want 3 times x, and not x here, but 5 times x. And I want it to be black. So here's my [INAUDIBLE] figure on top of the circle.
I've already shown you how to change color. There's a few things you can change. If you look at the plot help file, you will see there is a lot of information. But here's the information that I need for this. These are the letters for the colors. These are the letters for the markers I'll show you in a sec. And these are the symbols for the line style.
So let's see how that makes a difference. First I'll turn off the hold. So here, I've turned off the hold. And now I'm going to plot this with this type line style. So that's the dotted line style. And the markers going to be this right-pointing triangle.
I can also change the line width. There's a typo. There we go. That makes it a little bit difficult to see, so let's make a smaller line width. There we go. That's a nice, thick line, if we need such. You can also just change the marker size, if we need, without changing the line width.
You can have a title. We can add an x label and a y label. And we can change the axis. We can change the axis by using the magnifying glass. That was a double click to go back to the original view. Or I could change it directly from the command line by setting what I want the axis to be. So let's zoom into the first quadrant, x, x, y, y. There's the first quadrant, see? From 0 to 1, from 0 to-- this is the first quadrant.
I can work with multiple figures if I undock and close this windows. And what I'll do, is I'll make my MATLAB window small, so you can see where the figures are. Here we go. So here is the undocked figure.
I can work with multiple figures. I can open another figure, so here is another figure. So I have Figure 1 and Figure 2. And I can access them by either clicking on them before I issue my plot command, or from the command line, figure 2 will pop up Figure 2. And now, if I plot something, plot sine x cosine x in green, then it will plot it to this one.
I can change the location of these plots by looking at the following. So this tells me where this plot is. This is the starting x, starting y, width, and height. And I can change all of these by setting the position. So instead of what it is, let's set it to something else. So now it became this small thing. Let's bring it up a bit, so that you can see it too. There we go.
I can add text to my figure. I have to say what the x is, 0, what the y is, 0, and then what the text is. So that puts it at this point. 0, 0 is the beginning of the text.
I can clear the figure, without closing it. I can separate it into subplots. Let's say, one row of plots, two columns of plots. Here's the first plot. And in this first plot, I'm going to plot this one. And then the second plot, I will plot this one.
Oh, that's a bit messy. Let me make this bigger, so you can see what's going on. There you go, so here is a subplot. This is the first subplot. This is the second subplot. So, I encourage you to read the help files on all of the commands that you saw here today, as a way to learn how to deal with plotting in MATLAB.