Lesson 1.2: The MATLAB Environment (Old version)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
to run MATLAB got two options one you can use an installed version or two you can use an online version option one installed version requires that you get a license download a copy of the MATLAB installation package and install it on your computer all that'll take a bit of time and effort of course but if you're lucky enough to already have MATLAB on your computer as I do you're in great shape because you don't have to download or install anything you can get started immediately if on the other hand you do not already have MATLAB on your computer and you don't have a license for the installed version you're still lucky and you are in still in great shape because with option to the online version you never have to download or install anything and the best part is that the nice people at mathworks have decided that just for enrolling in this course they're going to give you a free 12-week license to use the online version of MATLAB which is called well it's called MATLAB online and it's really pretty slick to use it all you need is a web browser and you can use it on any computer anywhere anytime as often as you want to the two versions look a bit different but they both give you the same MATLAB language there's some functionality missing in MATLAB online but everything you need for this course is right there now before we get to MATLAB online and before we start doing actual exercises in MATLAB we're going to introduce installed MATLAB because that's the version you'll see me using throughout most of this course in fact when we recorded most of these lectures in late 2014 and early 2015 MATLAB online wasn't even available now I'm coming to you from March 2016 and MATLAB online is very much available so first you're going to see us introduce the installed MATLAB version which was the only version available when the rest of this video was recorded and then in the next video I'll explain MATLAB online and compare it to the Staal version if you're using the installed version then after this video is over you can skip the next one but if you're using the online version you'll need to watch both of them so now let's return to those dreamy days in the fall of 2014 and I was just beginning to talk about how to start to install MATLAB icon somewhere to click or double-click for example it might be on your Start menu in Windows or your Launchpad on a MacBook or on its dock or might be on your desktop as in this case as a matter of fact there are three icons on this MacBook desktop one for each of three versions of MATLAB that have been installed on this computer you can see over here are 2014 be our 2014 a-and our 2012 be we double-click any one of them say our 2014 be in MATLAB starts up and the MATLAB programming environment window opens up this window is also called a desktop it's matlab's desktop we'll be doing a lot of work on it the generic name for desktop is graphical user interface or using the initials as most programmers do we can call it a GUI spelled GUI like any decent GUI we can move it around so here there you go and we can change its shape and size by dragging the edges of the corners playing around that way I'm going to put it right where I like it there I'm using up the whole screen that way so got as much space as I possibly can get inside this GUI we see three sub windows the current folder over here on the left the command window in the middle and the workspace when I click in them they're labeled at the top lights up meaning that I've made them the active window this arrangement with the current folder on the left the workspace window on the right is the default layout for our 2014 a and B the default is somewhat different for earlier versions which you might have a lot of these will include a fourth window called the command history window to probably be over at the bottom right at the bottom left you can have that fourth window in the AR 2014 a and B and later versions too you just have to add it to the default layout we'll show you how to do that in a little bit also the windows default can be a bit different from the version for the apple operating system these differences are small enough though that they're unlikely to cause you any trouble so we'll just use one version in this course 2014 B which we're looking at right now that's the latest version available as we're recording these lessons which if you can see up here is in the late fall of 2014 well let's look at the current folder over here on the Left this is the place where MATLAB saves programs in the files and it's also the first place to look when it's looking for files at hold programs and it needs we can change the current folder to be another folder we can for example move up into the enclosing folder which is called the parent by clicking here on this tiny little folder icon it's got a little black arrow pointing up on it or we can go into a folder that's in the current folder MATLAB by clicking on that if you'd rather navigate using your operating systems folder explorer you can get to that by clicking this little icon here with the green arrow pointing down I'm going to do that and I'm going to navigate to a folder where I'm storing files for this course let's see over here in tutorials so I'll click open now you see I'm in a different directory here folder and directory are synonymous names for the same thing and over here right up here MATLAB provides an address bar shows you the current folder which is right here it's parent it's grandparent and so forth you can move to any of these folders by clicking them you can't go back down unless you come over here and click and way over here at the far right you see this little teeny triangle you can click on that and you can see recent places you've been you'll notice we were here at one point but I want to be here so I'm going to click there so that puts me back in the tutorials folder as you can see here and since this is lesson 1 I want to go to lesson 1 so I'm going to double click that one now we're in the folder called lesson 1 which is a child of the parent tutorials ok now we know how to move around we're finally ready to type our first MATLAB command to do that we first click somewhere in the command window if we click anywhere in the command window we'll see a little vertical bar that starts blinking on and off just to the right of this pair of greater-than signs here that pair of greater-than signs is matlab's prompt well and what's a prompt let's look it up in the textbook there we click on glossary and we see the first definition in the glossary that's abstract class that's an advanced concept that comes toward the end of this book where we introduced the object-oriented programming constructs in MATLAB object-oriented programming is one of those advanced concepts that we mentioned that are beyond the scope of this course so let's type prompt which is what we're looking for into this little search window here and then we'll click on prompt and there's our definition prompt is a symbol or symbols printed by a program MATLAB is an example to indicate that it's ready for input from the user of the program MATLAB uses the prompt greater than greater than and I want you to notice something if we go down here we can click here to find out where this term was introduced in the textbook and there it is and we see that it's right there where the command window is first introduced almost any textbook that talks about the command window is going to start off by talking about this prompt and that's what we do in the textbook and that's what we do in the course so let's get back to MATLAB before we type our first command right here you should know that if you ever need to regain control from MATLAB because it's taking too long to process a command you can type control C that's done by holding down the control key which may just have ctrl written on it and while you hold that key down hit the C key there I did it but nothing much happened other than going to a new line but I can tell you when you've made a mistake that causes MATLAB to pour out millions of numbers on the screen and it seems to be going on forever well like this let's suppose I type R and we'll explain R and later 1e 7 we'll explain that later I hit return and hold on goodness so numbers are just pouring out seems to be going on forever and so I'm going to stop this nonsense with ctrl C there I hit control C and stop MATLAB ctrl C is the all-powerful command in MATLAB Abbes also if you need to close MATLAB down completely you can type quit like this I'm not going to type quit so I'm gonna hit some deletes here get rid of it or you can simply close matlab's window by clicking in the X appear it's on the left and the Apple operating system it's over on the right and the Windows operating system but this is no time to quit okay the time has come for our first command I'm going to clear this screen using CLC and I'm ready to type a command so get ready this is it I'm going to type x equals 1 plus 2 now I'm going to hit the enter key here we go there well maybe I built that up a little bit too much but more is going on here than meets the eye what MATLAB is done is create a variable given it the name X calculated one plus two and gotten the value three stored the three and X and printed X's brand-new value in the command window if you look at every programming language provides variables and manages locations in the computer memory to store their values in fact the definition of a variable in computer programming is simply a location in memory that has a name and a value here's a little fancier definition from the glossary a named location in memory into which values can be stored computer science definition as opposed to mathematics definition mathematics definition is a little bit different we're not interested in that here we're interested in computer science definitions and let's look at another one we've just given this variable a value with an assignment statement it's defined in computer science like this statement of the form variable equals expression the means assign the value of the expression on the right side of the equal sign to the variable that's on the left side kind of goes from right to left the form of an assignment statement in MATLAB and in almost all computer languages for that matter is the same as it has been from the beginning in Fortran you type its name then the equal sign then an expression and once the variable is assigned a value like 3 in this case it'll keep that value until you change it ok let's get back to the command window again when we told MATLAB to assign 3 to X X didn't exist that's no problem MATLAB created it right on the spot you don't have to worry about creating variables and that's one of the things that makes MATLAB simple to use and one of the reasons molars students preferred it to Fortran I'm pretty sure Fortran like C C++ Java and many so-called compiled languages require a lot of setup work to create a variable but the sort of programs that are typically written with these other languages they're good reasons for requiring a lot of setup work but it's a lot easier to get a program written if you can get along without it and with MATLAB we can okay now let's just type our variables name without assigning anything to it we type X and hit enter this time MATLAB tells us the value of X that's all it does not so helpful now we just saw it but very helpful if you've given 50 commands since you assigned a value to X and you don't know what that value is now again there's a bit more going on it might be obvious here MATLAB has just searched its memory for the variable named X founded checked its value discovered that it's 3 and then printed the 3 in the command window now let's ask it to look for why why enter oops read type is never a good thing in MATLAB you know I've been programming MATLAB for 20 years and I still get a little sting when I see one of these read error messages anyway MATLAB is telling us the Y doesn't exist it says undefined function or variable Y says functional variable because functions can have names like Y or X to MATLAB thought maybe we're trying to run a function here a function is simply an operation that's invoked by giving its name you can look it up in the glossary there's no operation named Y and there's no variable named Y either so MATLAB complained not sure why MATLAB mentions function before variable maybe it's because it's alphabetical oh and by the way let's clear up any confusion between the word command and the word function they mean the same thing in MATLAB it's documentation doesn't distinguish between these two synonyms but it seems to use the word function more often than command ok the function Y doesn't exist but here's an example of a function that does exist clear why don't you look over here at the workspace and notice that X shows up in the workspace and its value is 3 I hit enter and it's gone in MATLAB the word workspace simply means the set of variables that we've created we just got rid of all our variables we just had one so the workspace is now empty let's put X back there again this time with a different value there we can see X its values 7000 let's look at X over here in the command window and yep it's 7000 and notice that checking X's value doesn't change anything in the workspace let's try looking for y we knew it would be an error making an error doesn't change anything either let's do something it does change the workspace let's set y equal X plus 105 so Y is seven thousand five and let's let zebra equal Y minus X you've got to add variables or to change their values or delete variables to change the workspace you can delete them by clicking the right button here on the thing you want to delete let's delete zebra it's gone now then if you don't believe it there but let's do but zebra again I can repeat that command by just hitting the up arrow key on my keyboard until I get to that command then hit return there it goes so I've given that command again and zebras back and we can clear it with the clear command this time we give it the name zebra and it just clears zebra leaves everything else there note that zebra is pink see here or is that purple MATLAB uses purplish pink to mean that the name zebra is being given to the command clear instead of the value five which the variable zebra had Cleary is not removing the five from the variable zebra it's removing the variable named zebra from the workspace and its values lost with it of course that's confusing forget it the reason for the color is not that important I just thought you I want to know that your eyes aren't playing tricks on you okay we've looked at the three windows in the desktop and the address bar above them there's also all that gray stuff above that up here this is where you find the so called tool strips and the most important one is the one on top by default it's called the home tool strip and here's its name you can get to the other two by clicking them like this we'll focus on the home strip in this course well look at many of the tools on this strip later but we'll postpone that until a couple lessons from now you can hide these tool strips if you want to by clicking this little tiny triangle with the line above it over here on the right when you do that the blue bar remains but the tool strips disappear and the windows down here get bigger that's useful when you're working on a small screen but since we have a big one we're going to click that triangle again and get them back you probably notice the little white area just to the left of the triangle that we clicked this is the search bar and it works like the typical search bar you can click in that area type words into it hit enter and if MATLAB has the information about the words you typed it'll pop that information up for example if we wanted to know about the clear command we might type clear command in here let's do that and hit return and a window pops up with the search results you can click on clear to see what the command does do that you can see that there's more than one way to call clear and there's examples over here you can click on these little links and it will show you examples in the meantime though let's talk about command history you remember I mentioned that to you before you can type command history in here if you want to see what it does and there's command history and there's information there but I'm going to talk to you about it and tell you how to do it I told you you can get the command history window to show up if you want to well here's how to do it click anywhere in the command window then click the up arrow on your keyboard there you remember I did this earlier to redo a zebra assignment when you do that you see a list of previous commands that you've issued these little red marks by these commands show that there was an error on those commands now if you want to repeat a command you just uh pair your way to it let's say I want to repeat um y equals x plus 5 there I hit enter and I repeated the command didn't accomplish much because Y is still seven thousand five but I did show you how to repeat a command what if you want to repeat a previous command but change it a bit say change X equals 1 plus 2 to x equals 3 plus 2 well let's just hit the up arrow and let's hit it until we get to the command we want to change there what we're going to do is arrow we're going to change the 1 to a 3 hit enter and we see x equals three plus two x equals five this is very useful when you have a long command that you want to alter slightly finally if you want the command history to show up in a window on the desktop as is the default and the older versions of MATLAB just click the up arrow on the keyboard now and then go up here with a mouse and click this little tiny down arrow come down here and click dock and there's the command history window right there well you can scroll up and down and you can click on commands and execute them over here in the command window I think I'll leave it there for awhile for old times sake oh and note that when we hit the up arrow we put the x equals three plus two command in the command window well I don't need to do that command again wouldn't hurt but I'll show you that you can delete it without executing it let's just click left sweep over it to highlight it and hit delete it's gone that can be important to know if you accidentally put a long command there shouldn't be re-executing
Info
Channel: Fitzle LLC
Views: 100,333
Rating: 4.9648814 out of 5
Keywords: MATLAB
Id: VheLmG7rh9w
Channel Id: undefined
Length: 23min 3sec (1383 seconds)
Published: Thu Apr 21 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.