1 00:00:06,750 --> 00:00:09,580 [? YOSSI FARJOUN: ?] This is [? Doctor ?] MATLAB, Lecture 4, 2 00:00:09,580 --> 00:00:10,680 Plotting. 3 00:00:10,680 --> 00:00:13,312 MATLAB is a great tool for making plots. 4 00:00:13,312 --> 00:00:14,270 You can plot your data. 5 00:00:14,270 --> 00:00:15,380 You can plot your results. 6 00:00:15,380 --> 00:00:17,282 You can make very elaborate plots. 7 00:00:17,282 --> 00:00:19,490 But first, we need to learn how to make simple plots. 8 00:00:19,490 --> 00:00:22,640 So let's start with a simple plot. 9 00:00:22,640 --> 00:00:27,820 Let's plot sine on several points between 0 and 2 pi. 10 00:00:35,720 --> 00:00:37,910 So here we go, I've made the points. 11 00:00:37,910 --> 00:00:40,730 I put x versus sine of x. 12 00:00:43,950 --> 00:00:47,380 I'm going to dock this figure. 13 00:00:47,380 --> 00:00:49,690 Great, so here is x versus sine x. 14 00:00:49,690 --> 00:00:55,210 I can do x versus cosine x. 15 00:00:55,210 --> 00:01:00,680 I can always also plot sine x versus cosine x. 16 00:01:00,680 --> 00:01:05,134 So the x is the sine, and the y is the cosine. 17 00:01:05,134 --> 00:01:05,800 And there it is. 18 00:01:05,800 --> 00:01:06,760 It's supposed to be a circle. 19 00:01:06,760 --> 00:01:08,260 It looks like an ellipse, but notice 20 00:01:08,260 --> 00:01:10,735 it goes from minus 1 to 1, and from minus 1 to 1. 21 00:01:10,735 --> 00:01:12,830 So if you want to make it look like a circle, 22 00:01:12,830 --> 00:01:17,560 you can issue the command axis square. 23 00:01:17,560 --> 00:01:20,140 That looks like a circle. 24 00:01:20,140 --> 00:01:22,390 But what if you wan it to be red circle? 25 00:01:22,390 --> 00:01:25,530 Then you can add the line style, r. 26 00:01:25,530 --> 00:01:27,280 You still have to tell it it to be square. 27 00:01:32,870 --> 00:01:37,520 You can put more than one command, more than one plot 28 00:01:37,520 --> 00:01:38,360 on one figure. 29 00:01:38,360 --> 00:01:45,430 So you can do the following, hold, 30 00:01:45,430 --> 00:01:46,750 so now it's going to be held. 31 00:01:46,750 --> 00:01:48,240 Hold toggles it. 32 00:01:48,240 --> 00:01:49,870 If you hold again, it will be off. 33 00:01:49,870 --> 00:01:52,375 So I'm going to hold, or you can say hold on, 34 00:01:52,375 --> 00:01:54,075 and that will definitely be on. 35 00:01:54,075 --> 00:01:59,050 And now, I want to plot, not x, but I want 3 times x, and not x 36 00:01:59,050 --> 00:02:01,490 here, but 5 times x. 37 00:02:01,490 --> 00:02:04,860 And I want it to be black. 38 00:02:04,860 --> 00:02:09,170 So here's my [INAUDIBLE] figure on top of the circle. 39 00:02:12,069 --> 00:02:13,860 I've already shown you how to change color. 40 00:02:13,860 --> 00:02:15,410 There's a few things you can change. 41 00:02:15,410 --> 00:02:21,650 If you look at the plot help file, 42 00:02:21,650 --> 00:02:23,580 you will see there is a lot of information. 43 00:02:23,580 --> 00:02:25,580 But here's the information that I need for this. 44 00:02:25,580 --> 00:02:28,770 These are the letters for the colors. 45 00:02:28,770 --> 00:02:31,470 These are the letters for the markers I'll show you in a sec. 46 00:02:31,470 --> 00:02:35,400 And these are the symbols for the line style. 47 00:02:35,400 --> 00:02:38,441 So let's see how that makes a difference. 48 00:02:38,441 --> 00:02:39,990 First I'll turn off the hold. 49 00:02:44,890 --> 00:02:47,150 So here, I've turned off the hold. 50 00:02:47,150 --> 00:02:51,770 And now I'm going to plot this with this type line style. 51 00:02:51,770 --> 00:02:54,930 So that's the dotted line style. 52 00:02:54,930 --> 00:02:59,580 And the markers going to be this right-pointing triangle. 53 00:03:04,300 --> 00:03:07,060 I can also change the line width. 54 00:03:11,820 --> 00:03:13,672 There's a typo. 55 00:03:13,672 --> 00:03:15,130 There we go. 56 00:03:15,130 --> 00:03:17,290 That makes it a little bit difficult to see, 57 00:03:17,290 --> 00:03:19,008 so let's make a smaller line width. 58 00:03:19,008 --> 00:03:20,460 There we go. 59 00:03:20,460 --> 00:03:24,956 That's a nice, thick line, if we need such. 60 00:03:24,956 --> 00:03:35,080 You can also just change the marker size, if we need, 61 00:03:35,080 --> 00:03:37,525 without changing the line width. 62 00:03:37,525 --> 00:03:38,400 You can have a title. 63 00:03:45,380 --> 00:03:53,530 We can add an x label and a y label. 64 00:04:03,450 --> 00:04:04,750 And we can change the axis. 65 00:04:04,750 --> 00:04:08,000 We can change the axis by using the magnifying glass. 66 00:04:10,648 --> 00:04:12,981 That was a double click to go back to the original view. 67 00:04:17,310 --> 00:04:21,390 Or I could change it directly from the command line 68 00:04:21,390 --> 00:04:23,200 by setting what I want the axis to be. 69 00:04:23,200 --> 00:04:31,150 So let's zoom into the first quadrant, x, x, y, y. 70 00:04:31,150 --> 00:04:33,130 There's the first quadrant, see? 71 00:04:33,130 --> 00:04:37,145 From 0 to 1, from 0 to-- 72 00:04:37,145 --> 00:04:38,270 this is the first quadrant. 73 00:04:44,470 --> 00:04:50,340 I can work with multiple figures if I undock 74 00:04:50,340 --> 00:04:53,060 and close this windows. 75 00:04:53,060 --> 00:04:56,740 And what I'll do, is I'll make my MATLAB window small, 76 00:04:56,740 --> 00:04:58,646 so you can see where the figures are. 77 00:05:01,502 --> 00:05:02,209 Here we go. 78 00:05:02,209 --> 00:05:03,500 So here is the undocked figure. 79 00:05:07,560 --> 00:05:09,345 I can work with multiple figures. 80 00:05:09,345 --> 00:05:11,605 I can open another figure, so here is another figure. 81 00:05:11,605 --> 00:05:13,300 So I have Figure 1 and Figure 2. 82 00:05:18,060 --> 00:05:22,190 And I can access them by either clicking on them 83 00:05:22,190 --> 00:05:26,450 before I issue my plot command, or from the command line, 84 00:05:26,450 --> 00:05:29,430 figure 2 will pop up Figure 2. 85 00:05:29,430 --> 00:05:37,736 And now, if I plot something, plot sine x cosine x in green, 86 00:05:37,736 --> 00:05:39,110 then it will plot it to this one. 87 00:05:41,810 --> 00:05:44,180 I can change the location of these plots 88 00:05:44,180 --> 00:05:45,864 by looking at the following. 89 00:05:49,736 --> 00:05:52,900 So this tells me where this plot is. 90 00:05:52,900 --> 00:05:56,395 This is the starting x, starting y, width, and height. 91 00:05:56,395 --> 00:06:04,510 And I can change all of these by setting the position. 92 00:06:04,510 --> 00:06:08,621 So instead of what it is, let's set it to something else. 93 00:06:16,980 --> 00:06:18,840 So now it became this small thing. 94 00:06:18,840 --> 00:06:22,580 Let's bring it up a bit, so that you can see it too. 95 00:06:22,580 --> 00:06:23,430 There we go. 96 00:06:26,650 --> 00:06:32,775 I can add text to my figure. 97 00:06:32,775 --> 00:06:38,550 I have to say what the x is, 0, what the y is, 0, 98 00:06:38,550 --> 00:06:41,830 and then what the text is. 99 00:06:41,830 --> 00:06:44,770 So that puts it at this point. 100 00:06:44,770 --> 00:06:46,605 0, 0 is the beginning of the text. 101 00:06:51,920 --> 00:06:55,490 I can clear the figure, without closing it. 102 00:06:55,490 --> 00:06:57,170 I can separate it into subplots. 103 00:06:59,880 --> 00:07:02,820 Let's say, one row of plots, two columns of plots. 104 00:07:02,820 --> 00:07:05,340 Here's the first plot. 105 00:07:05,340 --> 00:07:10,860 And in this first plot, I'm going to plot this one. 106 00:07:10,860 --> 00:07:16,038 And then the second plot, I will plot this one. 107 00:07:16,038 --> 00:07:17,220 Oh, that's a bit messy. 108 00:07:17,220 --> 00:07:19,631 Let me make this bigger, so you can see what's going on. 109 00:07:22,220 --> 00:07:24,680 There you go, so here is a subplot. 110 00:07:24,680 --> 00:07:25,790 This is the first subplot. 111 00:07:25,790 --> 00:07:28,390 This is the second subplot. 112 00:07:28,390 --> 00:07:30,400 So, I encourage you to read the help files 113 00:07:30,400 --> 00:07:33,350 on all of the commands that you saw here today, 114 00:07:33,350 --> 00:07:37,710 as a way to learn how to deal with plotting in MATLAB.