WEBVTT

00:00:06.750 --> 00:00:09.580
[? YOSSI FARJOUN: ?] This is
[? Doctor ?] MATLAB, Lecture 4,

00:00:09.580 --> 00:00:10.680
Plotting.

00:00:10.680 --> 00:00:13.312
MATLAB is a great
tool for making plots.

00:00:13.312 --> 00:00:14.270
You can plot your data.

00:00:14.270 --> 00:00:15.380
You can plot your results.

00:00:15.380 --> 00:00:17.282
You can make very
elaborate plots.

00:00:17.282 --> 00:00:19.490
But first, we need to learn
how to make simple plots.

00:00:19.490 --> 00:00:22.640
So let's start
with a simple plot.

00:00:22.640 --> 00:00:27.820
Let's plot sine on several
points between 0 and 2 pi.

00:00:35.720 --> 00:00:37.910
So here we go, I've
made the points.

00:00:37.910 --> 00:00:40.730
I put x versus sine of x.

00:00:43.950 --> 00:00:47.380
I'm going to dock this figure.

00:00:47.380 --> 00:00:49.690
Great, so here is
x versus sine x.

00:00:49.690 --> 00:00:55.210
I can do x versus cosine x.

00:00:55.210 --> 00:01:00.680
I can always also plot
sine x versus cosine x.

00:01:00.680 --> 00:01:05.134
So the x is the sine,
and the y is the cosine.

00:01:05.134 --> 00:01:05.800
And there it is.

00:01:05.800 --> 00:01:06.760
It's supposed to be a circle.

00:01:06.760 --> 00:01:08.260
It looks like an
ellipse, but notice

00:01:08.260 --> 00:01:10.735
it goes from minus 1 to
1, and from minus 1 to 1.

00:01:10.735 --> 00:01:12.830
So if you want to make
it look like a circle,

00:01:12.830 --> 00:01:17.560
you can issue the
command axis square.

00:01:17.560 --> 00:01:20.140
That looks like a circle.

00:01:20.140 --> 00:01:22.390
But what if you wan
it to be red circle?

00:01:22.390 --> 00:01:25.530
Then you can add
the line style, r.

00:01:25.530 --> 00:01:27.280
You still have to tell
it it to be square.

00:01:32.870 --> 00:01:37.520
You can put more than one
command, more than one plot

00:01:37.520 --> 00:01:38.360
on one figure.

00:01:38.360 --> 00:01:45.430
So you can do the
following, hold,

00:01:45.430 --> 00:01:46.750
so now it's going to be held.

00:01:46.750 --> 00:01:48.240
Hold toggles it.

00:01:48.240 --> 00:01:49.870
If you hold again,
it will be off.

00:01:49.870 --> 00:01:52.375
So I'm going to hold,
or you can say hold on,

00:01:52.375 --> 00:01:54.075
and that will definitely be on.

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

00:01:59.050 --> 00:02:01.490
here, but 5 times x.

00:02:01.490 --> 00:02:04.860
And I want it to be black.

00:02:04.860 --> 00:02:09.170
So here's my [INAUDIBLE]
figure on top of the circle.

00:02:12.069 --> 00:02:13.860
I've already shown you
how to change color.

00:02:13.860 --> 00:02:15.410
There's a few things
you can change.

00:02:15.410 --> 00:02:21.650
If you look at the
plot help file,

00:02:21.650 --> 00:02:23.580
you will see there is
a lot of information.

00:02:23.580 --> 00:02:25.580
But here's the information
that I need for this.

00:02:25.580 --> 00:02:28.770
These are the letters
for the colors.

00:02:28.770 --> 00:02:31.470
These are the letters for the
markers I'll show you in a sec.

00:02:31.470 --> 00:02:35.400
And these are the symbols
for the line style.

00:02:35.400 --> 00:02:38.441
So let's see how that
makes a difference.

00:02:38.441 --> 00:02:39.990
First I'll turn off the hold.

00:02:44.890 --> 00:02:47.150
So here, I've
turned off the hold.

00:02:47.150 --> 00:02:51.770
And now I'm going to plot this
with this type line style.

00:02:51.770 --> 00:02:54.930
So that's the dotted line style.

00:02:54.930 --> 00:02:59.580
And the markers going to be
this right-pointing triangle.

00:03:04.300 --> 00:03:07.060
I can also change
the line width.

00:03:11.820 --> 00:03:13.672
There's a typo.

00:03:13.672 --> 00:03:15.130
There we go.

00:03:15.130 --> 00:03:17.290
That makes it a little
bit difficult to see,

00:03:17.290 --> 00:03:19.008
so let's make a
smaller line width.

00:03:19.008 --> 00:03:20.460
There we go.

00:03:20.460 --> 00:03:24.956
That's a nice, thick
line, if we need such.

00:03:24.956 --> 00:03:35.080
You can also just change
the marker size, if we need,

00:03:35.080 --> 00:03:37.525
without changing the line width.

00:03:37.525 --> 00:03:38.400
You can have a title.

00:03:45.380 --> 00:03:53.530
We can add an x
label and a y label.

00:04:03.450 --> 00:04:04.750
And we can change the axis.

00:04:04.750 --> 00:04:08.000
We can change the axis by
using the magnifying glass.

00:04:10.648 --> 00:04:12.981
That was a double click to
go back to the original view.

00:04:17.310 --> 00:04:21.390
Or I could change it directly
from the command line

00:04:21.390 --> 00:04:23.200
by setting what I
want the axis to be.

00:04:23.200 --> 00:04:31.150
So let's zoom into the
first quadrant, x, x, y, y.

00:04:31.150 --> 00:04:33.130
There's the first quadrant, see?

00:04:33.130 --> 00:04:37.145
From 0 to 1, from 0 to--

00:04:37.145 --> 00:04:38.270
this is the first quadrant.

00:04:44.470 --> 00:04:50.340
I can work with multiple
figures if I undock

00:04:50.340 --> 00:04:53.060
and close this windows.

00:04:53.060 --> 00:04:56.740
And what I'll do, is I'll
make my MATLAB window small,

00:04:56.740 --> 00:04:58.646
so you can see where
the figures are.

00:05:01.502 --> 00:05:02.209
Here we go.

00:05:02.209 --> 00:05:03.500
So here is the undocked figure.

00:05:07.560 --> 00:05:09.345
I can work with
multiple figures.

00:05:09.345 --> 00:05:11.605
I can open another figure,
so here is another figure.

00:05:11.605 --> 00:05:13.300
So I have Figure 1 and Figure 2.

00:05:18.060 --> 00:05:22.190
And I can access them by
either clicking on them

00:05:22.190 --> 00:05:26.450
before I issue my plot command,
or from the command line,

00:05:26.450 --> 00:05:29.430
figure 2 will pop up Figure 2.

00:05:29.430 --> 00:05:37.736
And now, if I plot something,
plot sine x cosine x in green,

00:05:37.736 --> 00:05:39.110
then it will plot
it to this one.

00:05:41.810 --> 00:05:44.180
I can change the
location of these plots

00:05:44.180 --> 00:05:45.864
by looking at the following.

00:05:49.736 --> 00:05:52.900
So this tells me
where this plot is.

00:05:52.900 --> 00:05:56.395
This is the starting x,
starting y, width, and height.

00:05:56.395 --> 00:06:04.510
And I can change all of these
by setting the position.

00:06:04.510 --> 00:06:08.621
So instead of what it is,
let's set it to something else.

00:06:16.980 --> 00:06:18.840
So now it became
this small thing.

00:06:18.840 --> 00:06:22.580
Let's bring it up a bit,
so that you can see it too.

00:06:22.580 --> 00:06:23.430
There we go.

00:06:26.650 --> 00:06:32.775
I can add text to my figure.

00:06:32.775 --> 00:06:38.550
I have to say what the x
is, 0, what the y is, 0,

00:06:38.550 --> 00:06:41.830
and then what the text is.

00:06:41.830 --> 00:06:44.770
So that puts it at this point.

00:06:44.770 --> 00:06:46.605
0, 0 is the beginning
of the text.

00:06:51.920 --> 00:06:55.490
I can clear the figure,
without closing it.

00:06:55.490 --> 00:06:57.170
I can separate it into subplots.

00:06:59.880 --> 00:07:02.820
Let's say, one row of
plots, two columns of plots.

00:07:02.820 --> 00:07:05.340
Here's the first plot.

00:07:05.340 --> 00:07:10.860
And in this first plot,
I'm going to plot this one.

00:07:10.860 --> 00:07:16.038
And then the second plot,
I will plot this one.

00:07:16.038 --> 00:07:17.220
Oh, that's a bit messy.

00:07:17.220 --> 00:07:19.631
Let me make this bigger, so
you can see what's going on.

00:07:22.220 --> 00:07:24.680
There you go, so
here is a subplot.

00:07:24.680 --> 00:07:25.790
This is the first subplot.

00:07:25.790 --> 00:07:28.390
This is the second subplot.

00:07:28.390 --> 00:07:30.400
So, I encourage you
to read the help files

00:07:30.400 --> 00:07:33.350
on all of the commands
that you saw here today,

00:07:33.350 --> 00:07:37.710
as a way to learn how to
deal with plotting in MATLAB.