WEBVTT

00:00:07.360 --> 00:00:09.430
YOSSI FARJOUN: This is
Dr. MATLAB, lecture two,

00:00:09.430 --> 00:00:11.570
The Command Prompt.

00:00:11.570 --> 00:00:13.420
If you're like me,
you'll find yourself

00:00:13.420 --> 00:00:16.699
on the command line a lot
when you're working MATLAB,

00:00:16.699 --> 00:00:18.490
so it's important to
know how to get around

00:00:18.490 --> 00:00:20.380
on the command prompt.

00:00:20.380 --> 00:00:23.710
The first thing I want to show
you is how to use the arrows.

00:00:23.710 --> 00:00:25.455
Say I want to plot something.

00:00:35.460 --> 00:00:41.797
So I want to plot sin of 2x
between 0 and pi on 200 points.

00:00:41.797 --> 00:00:42.630
This is what I type.

00:00:45.410 --> 00:00:48.090
Of course, I typed
it with a typo.

00:00:48.090 --> 00:00:50.050
I forgot to put
the multiplication

00:00:50.050 --> 00:00:53.080
sign between the 2
and the x up here.

00:00:53.080 --> 00:00:56.450
So we've already seen
in the previous lecture

00:00:56.450 --> 00:00:58.970
that instead of typing
the whole thing,

00:00:58.970 --> 00:01:03.440
I press the up command,
the up arrow, which

00:01:03.440 --> 00:01:05.630
brings up the previous command.

00:01:05.630 --> 00:01:08.480
And then with the left
arrow, I can place the cursor

00:01:08.480 --> 00:01:12.335
where I need it to be
and insert the asterisk.

00:01:16.100 --> 00:01:19.160
I forgot to put the
semi-colon, so again, I

00:01:19.160 --> 00:01:23.720
press up at the semi-colon
and now I have what I wanted.

00:01:23.720 --> 00:01:29.330
Now I plot x and y
and I get my plot.

00:01:29.330 --> 00:01:31.960
I'll put it into the window.

00:01:31.960 --> 00:01:33.910
Here it is.

00:01:33.910 --> 00:01:35.440
Great.

00:01:35.440 --> 00:01:38.230
Now unlike this plot, I
want to see the points,

00:01:38.230 --> 00:01:44.611
so I'm going to press up
and modify the plot command.

00:01:44.611 --> 00:01:45.610
And now I see the point.

00:01:45.610 --> 00:01:48.180
And I still don't see the point
because I plotted to many.

00:01:48.180 --> 00:01:50.700
So I, again, pressed
the up command.

00:01:50.700 --> 00:01:53.010
I know I can press
the up command twice

00:01:53.010 --> 00:01:54.479
to reach this line,
but what I want

00:01:54.479 --> 00:01:56.520
to show you is what happens
when you press the up

00:01:56.520 --> 00:01:59.230
command after I started
typing x equals.

00:01:59.230 --> 00:02:02.880
See this x equals is the
same as this x equals here.

00:02:02.880 --> 00:02:07.240
When I press up, the first
line that starts with x equals

00:02:07.240 --> 00:02:09.030
will show up.

00:02:09.030 --> 00:02:11.200
Here it is, if I
press up again, it

00:02:11.200 --> 00:02:13.140
will be the one
without the semicolon.

00:02:13.140 --> 00:02:16.430
If I press up again, it will be
the one without the asterisk.

00:02:16.430 --> 00:02:18.170
Let me go back down
to the one I want.

00:02:18.170 --> 00:02:20.000
This is the one I want.

00:02:20.000 --> 00:02:22.760
Now I want to change this 200
to something smaller, say five.

00:02:22.760 --> 00:02:27.650
So I could press the left area
until I reached there, and put

00:02:27.650 --> 00:02:28.850
50 points.

00:02:31.430 --> 00:02:35.740
And now plot again p, up, plot.

00:02:35.740 --> 00:02:36.810
Now 50 points.

00:02:36.810 --> 00:02:40.590
But here is a faster
way to get to that 50.

00:02:40.590 --> 00:02:43.185
Again, x, up-- now I
want to get to the 50,

00:02:43.185 --> 00:02:45.240
so instead of moving
with the left,

00:02:45.240 --> 00:02:48.390
I will move with
control left, and that

00:02:48.390 --> 00:02:51.160
moves one word at a time.

00:02:51.160 --> 00:02:52.830
In this case, it's
not a big difference,

00:02:52.830 --> 00:02:54.360
but sometimes it can be.

00:02:54.360 --> 00:02:56.620
See, it skips the whole word.

00:02:56.620 --> 00:03:00.510
It's skipping pi, it's
skipping linspace,

00:03:00.510 --> 00:03:02.830
it's skipping the whole 50.

00:03:02.830 --> 00:03:05.910
Let me put a 20 here.

00:03:05.910 --> 00:03:09.794
And now I want to
plot red points.

00:03:09.794 --> 00:03:12.317
And I have that.

00:03:12.317 --> 00:03:14.150
Another thing you can
do on the command line

00:03:14.150 --> 00:03:20.520
is to use Control-A. Control-A
for the beginning of the line,

00:03:20.520 --> 00:03:22.520
to move the cursor to the
beginning of the line,

00:03:22.520 --> 00:03:26.591
and Control-E to move the
cursor to the end of the line.

00:03:26.591 --> 00:03:29.010
Control-A for the beginning
of the line, Control-E

00:03:29.010 --> 00:03:31.660
for the end of the line.

00:03:31.660 --> 00:03:33.910
You can also cut and paste.

00:03:33.910 --> 00:03:43.700
With a shift, I select
Command-C to copy.

00:03:43.700 --> 00:03:46.870
Let's start a new line,
Command-V to paste.

00:03:49.444 --> 00:03:50.860
Depending on the
operating system,

00:03:50.860 --> 00:03:52.905
those commands might
be a bit different.

00:03:58.950 --> 00:04:00.840
Another thing you
might want to look at

00:04:00.840 --> 00:04:02.770
is the tab completion property.

00:04:02.770 --> 00:04:11.450
So if I start typing linspace,
I type lin s and now I hit Tab.

00:04:11.450 --> 00:04:13.260
MATLAB will show
all the commands

00:04:13.260 --> 00:04:15.670
it knows that start with
Lin s, in this case,

00:04:15.670 --> 00:04:17.820
linsolve and linspace.

00:04:17.820 --> 00:04:20.500
Of course the one
I want is linspace.

00:04:20.500 --> 00:04:21.943
If I want to find
help on this, I

00:04:21.943 --> 00:04:24.250
can press Control-A, move to
the beginning of the line,

00:04:24.250 --> 00:04:30.410
add help, add help,
and then hit Enter.

00:04:30.410 --> 00:04:33.010
Of course I can't see anything,
so I'll close this window.

00:04:33.010 --> 00:04:36.460
And here is the
help on linspace.

00:04:36.460 --> 00:04:40.100
And these are the two
ways you can use linspace.

00:04:40.100 --> 00:04:42.090
You give it the lower
and the upper limit,

00:04:42.090 --> 00:04:43.980
that gives you 100
points, equally

00:04:43.980 --> 00:04:45.270
spaced between those two.

00:04:45.270 --> 00:04:47.970
Or you give the
lower and upper limit

00:04:47.970 --> 00:04:50.110
and how many points
you want, and it

00:04:50.110 --> 00:04:51.330
get you that many points.

00:04:51.330 --> 00:04:59.600
For example, linspace,
0 to 10, five points.

00:04:59.600 --> 00:05:03.670
Here are five points equally
space between 0 to 10.

00:05:03.670 --> 00:05:07.320
Another thing that the help
file shows you are related

00:05:07.320 --> 00:05:09.520
commands that you might
want to read up on.

00:05:09.520 --> 00:05:12.800
So I encourage you to read
up on logspace and the colon

00:05:12.800 --> 00:05:14.330
function--

00:05:14.330 --> 00:05:17.290
it's actually the
colon operator,

00:05:17.290 --> 00:05:21.220
which is a very
complicated help file--

00:05:21.220 --> 00:05:24.560
and see why linspace is
related to colon and logspace.

00:05:27.190 --> 00:05:29.500
Another important feature
of the command line

00:05:29.500 --> 00:05:34.180
is the use of Control-C.
So it has two main things.

00:05:34.180 --> 00:05:37.552
For example, if you
have typed something,

00:05:37.552 --> 00:05:40.161
let's say I've
typed this, and I've

00:05:40.161 --> 00:05:41.910
decided I don't want
any of it, I actually

00:05:41.910 --> 00:05:43.820
went to do something else.

00:05:43.820 --> 00:05:45.940
So what I should do is
clear the whole line.

00:05:45.940 --> 00:05:47.580
I don't even want
to execute this.

00:05:47.580 --> 00:05:49.670
So to clear the whole
line without executing it,

00:05:49.670 --> 00:05:53.770
I'm going to press Control-C.
That clears that line.

00:05:53.770 --> 00:05:56.930
Control-C can also be used
to abort certain operations.

00:05:56.930 --> 00:06:07.250
For example, if I say x equals
1 while 1x equals x plus 1.

00:06:07.250 --> 00:06:09.610
So this is going to
add x all the time.

00:06:09.610 --> 00:06:11.500
As you see, x is
going to be growing

00:06:11.500 --> 00:06:14.216
and growing and growing
and growing forever.

00:06:14.216 --> 00:06:16.390
Now I want to stop
this at some point.

00:06:16.390 --> 00:06:19.630
So to stop it, really
the only thing I can do

00:06:19.630 --> 00:06:22.960
is to press Control-C. You
see while it's running,

00:06:22.960 --> 00:06:25.954
MATLAB says that it's busy.

00:06:25.954 --> 00:06:28.120
Sometimes it will be busy
and you won't even see it.

00:06:28.120 --> 00:06:29.270
Let's try that again.

00:06:29.270 --> 00:06:31.735
X equals 1 while 1--

00:06:34.240 --> 00:06:37.060
now I'll do it with a semicolon,
so I'll suppress output,

00:06:37.060 --> 00:06:38.811
but it will still be doing it.

00:06:38.811 --> 00:06:39.310
End.

00:06:39.310 --> 00:06:40.275
So now MATLAB is busy.

00:06:40.275 --> 00:06:41.900
It's not typing
anything on the screen,

00:06:41.900 --> 00:06:43.358
but it's doing the
same calculation

00:06:43.358 --> 00:06:46.570
that you saw before, except
it's not printing it out.

00:06:46.570 --> 00:06:50.110
Again, to abort this,
we press Control-C.

00:06:50.110 --> 00:06:51.580
You find out what x we got to.

00:06:51.580 --> 00:06:53.359
We counted quite high.

00:06:53.359 --> 00:06:55.150
We counted much higher
than here because we

00:06:55.150 --> 00:06:56.108
didn't have to display.

00:06:59.600 --> 00:07:03.900
If you're typing some other
command with a multi-line,

00:07:03.900 --> 00:07:08.840
i equals 1 to 100, j equals
i plus 2, for example.

00:07:12.410 --> 00:07:13.904
And midway through
that statement,

00:07:13.904 --> 00:07:15.320
you've decided
that you don't want

00:07:15.320 --> 00:07:17.779
to do it, again just
as before, pressing

00:07:17.779 --> 00:07:19.070
Enter is not going to help you.

00:07:19.070 --> 00:07:21.320
You're not going to get a
command prompt in this case.

00:07:21.320 --> 00:07:25.130
You can end it with an end
because you started with a for,

00:07:25.130 --> 00:07:27.920
or you could just
press Control-C.