1 00:00:07,360 --> 00:00:09,430 YOSSI FARJOUN: This is Dr. MATLAB, lecture two, 2 00:00:09,430 --> 00:00:11,570 The Command Prompt. 3 00:00:11,570 --> 00:00:13,420 If you're like me, you'll find yourself 4 00:00:13,420 --> 00:00:16,699 on the command line a lot when you're working MATLAB, 5 00:00:16,699 --> 00:00:18,490 so it's important to know how to get around 6 00:00:18,490 --> 00:00:20,380 on the command prompt. 7 00:00:20,380 --> 00:00:23,710 The first thing I want to show you is how to use the arrows. 8 00:00:23,710 --> 00:00:25,455 Say I want to plot something. 9 00:00:35,460 --> 00:00:41,797 So I want to plot sin of 2x between 0 and pi on 200 points. 10 00:00:41,797 --> 00:00:42,630 This is what I type. 11 00:00:45,410 --> 00:00:48,090 Of course, I typed it with a typo. 12 00:00:48,090 --> 00:00:50,050 I forgot to put the multiplication 13 00:00:50,050 --> 00:00:53,080 sign between the 2 and the x up here. 14 00:00:53,080 --> 00:00:56,450 So we've already seen in the previous lecture 15 00:00:56,450 --> 00:00:58,970 that instead of typing the whole thing, 16 00:00:58,970 --> 00:01:03,440 I press the up command, the up arrow, which 17 00:01:03,440 --> 00:01:05,630 brings up the previous command. 18 00:01:05,630 --> 00:01:08,480 And then with the left arrow, I can place the cursor 19 00:01:08,480 --> 00:01:12,335 where I need it to be and insert the asterisk. 20 00:01:16,100 --> 00:01:19,160 I forgot to put the semi-colon, so again, I 21 00:01:19,160 --> 00:01:23,720 press up at the semi-colon and now I have what I wanted. 22 00:01:23,720 --> 00:01:29,330 Now I plot x and y and I get my plot. 23 00:01:29,330 --> 00:01:31,960 I'll put it into the window. 24 00:01:31,960 --> 00:01:33,910 Here it is. 25 00:01:33,910 --> 00:01:35,440 Great. 26 00:01:35,440 --> 00:01:38,230 Now unlike this plot, I want to see the points, 27 00:01:38,230 --> 00:01:44,611 so I'm going to press up and modify the plot command. 28 00:01:44,611 --> 00:01:45,610 And now I see the point. 29 00:01:45,610 --> 00:01:48,180 And I still don't see the point because I plotted to many. 30 00:01:48,180 --> 00:01:50,700 So I, again, pressed the up command. 31 00:01:50,700 --> 00:01:53,010 I know I can press the up command twice 32 00:01:53,010 --> 00:01:54,479 to reach this line, but what I want 33 00:01:54,479 --> 00:01:56,520 to show you is what happens when you press the up 34 00:01:56,520 --> 00:01:59,230 command after I started typing x equals. 35 00:01:59,230 --> 00:02:02,880 See this x equals is the same as this x equals here. 36 00:02:02,880 --> 00:02:07,240 When I press up, the first line that starts with x equals 37 00:02:07,240 --> 00:02:09,030 will show up. 38 00:02:09,030 --> 00:02:11,200 Here it is, if I press up again, it 39 00:02:11,200 --> 00:02:13,140 will be the one without the semicolon. 40 00:02:13,140 --> 00:02:16,430 If I press up again, it will be the one without the asterisk. 41 00:02:16,430 --> 00:02:18,170 Let me go back down to the one I want. 42 00:02:18,170 --> 00:02:20,000 This is the one I want. 43 00:02:20,000 --> 00:02:22,760 Now I want to change this 200 to something smaller, say five. 44 00:02:22,760 --> 00:02:27,650 So I could press the left area until I reached there, and put 45 00:02:27,650 --> 00:02:28,850 50 points. 46 00:02:31,430 --> 00:02:35,740 And now plot again p, up, plot. 47 00:02:35,740 --> 00:02:36,810 Now 50 points. 48 00:02:36,810 --> 00:02:40,590 But here is a faster way to get to that 50. 49 00:02:40,590 --> 00:02:43,185 Again, x, up-- now I want to get to the 50, 50 00:02:43,185 --> 00:02:45,240 so instead of moving with the left, 51 00:02:45,240 --> 00:02:48,390 I will move with control left, and that 52 00:02:48,390 --> 00:02:51,160 moves one word at a time. 53 00:02:51,160 --> 00:02:52,830 In this case, it's not a big difference, 54 00:02:52,830 --> 00:02:54,360 but sometimes it can be. 55 00:02:54,360 --> 00:02:56,620 See, it skips the whole word. 56 00:02:56,620 --> 00:03:00,510 It's skipping pi, it's skipping linspace, 57 00:03:00,510 --> 00:03:02,830 it's skipping the whole 50. 58 00:03:02,830 --> 00:03:05,910 Let me put a 20 here. 59 00:03:05,910 --> 00:03:09,794 And now I want to plot red points. 60 00:03:09,794 --> 00:03:12,317 And I have that. 61 00:03:12,317 --> 00:03:14,150 Another thing you can do on the command line 62 00:03:14,150 --> 00:03:20,520 is to use Control-A. Control-A for the beginning of the line, 63 00:03:20,520 --> 00:03:22,520 to move the cursor to the beginning of the line, 64 00:03:22,520 --> 00:03:26,591 and Control-E to move the cursor to the end of the line. 65 00:03:26,591 --> 00:03:29,010 Control-A for the beginning of the line, Control-E 66 00:03:29,010 --> 00:03:31,660 for the end of the line. 67 00:03:31,660 --> 00:03:33,910 You can also cut and paste. 68 00:03:33,910 --> 00:03:43,700 With a shift, I select Command-C to copy. 69 00:03:43,700 --> 00:03:46,870 Let's start a new line, Command-V to paste. 70 00:03:49,444 --> 00:03:50,860 Depending on the operating system, 71 00:03:50,860 --> 00:03:52,905 those commands might be a bit different. 72 00:03:58,950 --> 00:04:00,840 Another thing you might want to look at 73 00:04:00,840 --> 00:04:02,770 is the tab completion property. 74 00:04:02,770 --> 00:04:11,450 So if I start typing linspace, I type lin s and now I hit Tab. 75 00:04:11,450 --> 00:04:13,260 MATLAB will show all the commands 76 00:04:13,260 --> 00:04:15,670 it knows that start with Lin s, in this case, 77 00:04:15,670 --> 00:04:17,820 linsolve and linspace. 78 00:04:17,820 --> 00:04:20,500 Of course the one I want is linspace. 79 00:04:20,500 --> 00:04:21,943 If I want to find help on this, I 80 00:04:21,943 --> 00:04:24,250 can press Control-A, move to the beginning of the line, 81 00:04:24,250 --> 00:04:30,410 add help, add help, and then hit Enter. 82 00:04:30,410 --> 00:04:33,010 Of course I can't see anything, so I'll close this window. 83 00:04:33,010 --> 00:04:36,460 And here is the help on linspace. 84 00:04:36,460 --> 00:04:40,100 And these are the two ways you can use linspace. 85 00:04:40,100 --> 00:04:42,090 You give it the lower and the upper limit, 86 00:04:42,090 --> 00:04:43,980 that gives you 100 points, equally 87 00:04:43,980 --> 00:04:45,270 spaced between those two. 88 00:04:45,270 --> 00:04:47,970 Or you give the lower and upper limit 89 00:04:47,970 --> 00:04:50,110 and how many points you want, and it 90 00:04:50,110 --> 00:04:51,330 get you that many points. 91 00:04:51,330 --> 00:04:59,600 For example, linspace, 0 to 10, five points. 92 00:04:59,600 --> 00:05:03,670 Here are five points equally space between 0 to 10. 93 00:05:03,670 --> 00:05:07,320 Another thing that the help file shows you are related 94 00:05:07,320 --> 00:05:09,520 commands that you might want to read up on. 95 00:05:09,520 --> 00:05:12,800 So I encourage you to read up on logspace and the colon 96 00:05:12,800 --> 00:05:14,330 function-- 97 00:05:14,330 --> 00:05:17,290 it's actually the colon operator, 98 00:05:17,290 --> 00:05:21,220 which is a very complicated help file-- 99 00:05:21,220 --> 00:05:24,560 and see why linspace is related to colon and logspace. 100 00:05:27,190 --> 00:05:29,500 Another important feature of the command line 101 00:05:29,500 --> 00:05:34,180 is the use of Control-C. So it has two main things. 102 00:05:34,180 --> 00:05:37,552 For example, if you have typed something, 103 00:05:37,552 --> 00:05:40,161 let's say I've typed this, and I've 104 00:05:40,161 --> 00:05:41,910 decided I don't want any of it, I actually 105 00:05:41,910 --> 00:05:43,820 went to do something else. 106 00:05:43,820 --> 00:05:45,940 So what I should do is clear the whole line. 107 00:05:45,940 --> 00:05:47,580 I don't even want to execute this. 108 00:05:47,580 --> 00:05:49,670 So to clear the whole line without executing it, 109 00:05:49,670 --> 00:05:53,770 I'm going to press Control-C. That clears that line. 110 00:05:53,770 --> 00:05:56,930 Control-C can also be used to abort certain operations. 111 00:05:56,930 --> 00:06:07,250 For example, if I say x equals 1 while 1x equals x plus 1. 112 00:06:07,250 --> 00:06:09,610 So this is going to add x all the time. 113 00:06:09,610 --> 00:06:11,500 As you see, x is going to be growing 114 00:06:11,500 --> 00:06:14,216 and growing and growing and growing forever. 115 00:06:14,216 --> 00:06:16,390 Now I want to stop this at some point. 116 00:06:16,390 --> 00:06:19,630 So to stop it, really the only thing I can do 117 00:06:19,630 --> 00:06:22,960 is to press Control-C. You see while it's running, 118 00:06:22,960 --> 00:06:25,954 MATLAB says that it's busy. 119 00:06:25,954 --> 00:06:28,120 Sometimes it will be busy and you won't even see it. 120 00:06:28,120 --> 00:06:29,270 Let's try that again. 121 00:06:29,270 --> 00:06:31,735 X equals 1 while 1-- 122 00:06:34,240 --> 00:06:37,060 now I'll do it with a semicolon, so I'll suppress output, 123 00:06:37,060 --> 00:06:38,811 but it will still be doing it. 124 00:06:38,811 --> 00:06:39,310 End. 125 00:06:39,310 --> 00:06:40,275 So now MATLAB is busy. 126 00:06:40,275 --> 00:06:41,900 It's not typing anything on the screen, 127 00:06:41,900 --> 00:06:43,358 but it's doing the same calculation 128 00:06:43,358 --> 00:06:46,570 that you saw before, except it's not printing it out. 129 00:06:46,570 --> 00:06:50,110 Again, to abort this, we press Control-C. 130 00:06:50,110 --> 00:06:51,580 You find out what x we got to. 131 00:06:51,580 --> 00:06:53,359 We counted quite high. 132 00:06:53,359 --> 00:06:55,150 We counted much higher than here because we 133 00:06:55,150 --> 00:06:56,108 didn't have to display. 134 00:06:59,600 --> 00:07:03,900 If you're typing some other command with a multi-line, 135 00:07:03,900 --> 00:07:08,840 i equals 1 to 100, j equals i plus 2, for example. 136 00:07:12,410 --> 00:07:13,904 And midway through that statement, 137 00:07:13,904 --> 00:07:15,320 you've decided that you don't want 138 00:07:15,320 --> 00:07:17,779 to do it, again just as before, pressing 139 00:07:17,779 --> 00:07:19,070 Enter is not going to help you. 140 00:07:19,070 --> 00:07:21,320 You're not going to get a command prompt in this case. 141 00:07:21,320 --> 00:07:25,130 You can end it with an end because you started with a for, 142 00:07:25,130 --> 00:07:27,920 or you could just press Control-C.