Transcript for:
lecture 1

to be joining all right so today is our first session for uh introduction to matlab we're going to cover some of the basic concepts of data processing in matlab and then we're going to basically show you what the matlab environment looks like give you access to use matlab on one of the computers at dvc and hopefully get you started on using matlab so hopefully today will prepare you to write your own matlab program in the coming session on tuesday let's just begin by sharing my powerpoint presentation and we go over the powerpoint presentation uh first before we introduce the matlab environment all right the first thing to remember that data in matlab is organized in rows and columns which we call them arrays so for example if you have five numbers those numbers could be written in a row orientation or in a column orientation to give you a visual reference look at this one here this is a collection of data that you can imagine to be placed in rows and column orientations and then this collection of the data as a whole is going to have one single name in this case the entire name uh the name of the entire collection is called a-r-r-a-a-r-r and this a-i-r is a collection of four rows of date and five columns of data four rays of data rows of data and five and five columns of data and then in order to refer to any single number within that collection of data we use two indices we use a row index and a column index so therefore if you look at this element here that we're looking at in green color that would be referred to by the same name so arr and then inside the parentheses we'll have two values one represents the row location and the second one represents the column rotation since this number is on third row and second column then it has an index of three comma two uh this very last value here on the lower right corner that value is referred to as array index of 4 comma 5. so this box here is having an index of four comma phi now arrays are fundamental to matlab you know matlab takes any data even a single value data as a same one row and one column and it represents it as an array so a single number which we call him a scalar as i mentioned it's also an array now indices as was mentioned up there begins with row first and column next so row first and column next and these indices always start with one which means we always have a row one and a column one okay now we can divide arrays into two categories one called vectors and the other one called matrices vectors and matrices first of all vectors are arrays that have only one dimension meaning data in them is arranged in either a row orientation or a column orientation so vector is a special form of array that has only one dimension matrix is an array that has more than one dimension two dimensions three dimensions and so on very often you would see that we're going to use name array vectors and matrices interchangeably but they are really having differences in the way that we look at them and i want you to see that you know arrays and vectors are the same thing because vectors is a special form of the array that has one dimension and arrays and matrix matrices the same also matrices have more than one dimensions okay so if you see in your textbook or in our conversation that we say vector or matrix or array we're really referring to the same thing now the size of an array is typically specified by the number of rows and number of columns so if you have n rows and m columns in an array the size of that array is n times m for the example that i gave you on the previous slide we had four rows and five columns so four times five is 20 and there are 20 elements in our array in that case all right so let's look at this uh array here as you can see it's it's collection of data it has three rows and two columns and therefore its size is six three times two or the next one b array b is a vector is one dimensional it has one row and four columns and therefore the size is four one times four b is a column vector and it has three rows and one column so its size is three times one or three all right once you have an array such as a b or c defined then you can refer to each value within that array so each element can be referred to by one index or by two indices if you use one index you're referring to element number and element numbers are counted across columns in matlab so let's look at a here element number one of a is this one here element number two is three across column element number three is five element number four then is the next column four two element number five is four element number six is six so that's one way of referring to these elements the other way of referring to these elements is to give two indices that you saw earlier the row location and the column location so for example if you're interested in this five year that is a parenthesis three which is row location comma one which is the column location so therefore when we talk about b3 we're looking at because we're using one number here we're talking about element numbers and therefore that would mean this value here element 1 two three and that would be this three when we talk about c2 we're looking at element number two of c so this is a column array we go all the way down here and then we will see three as the second element uh sorry and also for for example a21 we're referring to second row column one so that's three and that will also be equal to 3 in this case all right so remember how you refer to elements of arrays either by one number representing element number or by two numbers representing row and column locations and also as i mentioned element numbers are counted across column from the first column then next column and so on and so forth any questions folks all right now the concept of variables variables basically are a way of referring to a portion of the memory on your computer which contains some data and it has a name assigned to it so variables therefore represent data for us represent memory location and data the name that you can assign well the content of the memory can change from from one moment to another moment but we still refer to that same memory by the same name the name that you assigned to your variables would have to follow a specific guidelines first of all they have to begin with a letter and then you could have other characters that will follow them and these characters would either have to be alphanumeric which means alphabetic no characters and numbers or it has it can be an underscore no other characters can be accepted for a name so for example you could say x x starts with a letter and can be can represent a location on our memory on our computer memory you could also say x2 x2 as one board is also another name x underscore 2 is also another name and acceptable 2x is not acceptable because that name begins with a number and the name has to begin with a letter so x dollar sign is also not acceptable because the only special character that we can have is the underscore in the name so you may call names with longer characters for example you could call a memory location a test you could call a memory location george you could call a memory location today is today underscore is under a score thursday why did i use underscore between those words today is and thursday because we cannot have blank characters in a name the only a special character that we can have is under a score so therefore if you have a long name with different words in that name you have to separate it from each other by an underscore and that's why i said today under a score is underscore thursday is can be considered a name no matter how long the name uh you the name that you assigned to the memory location is matlab is going to only uh consider the first 31 characters the first 31 characters those are the significant ones and matlab ignores the rest as a matter of style you are not supposed to have a name that is one of the key words that matlab uses for a specific purpose in order to see the list of these keywords you can on the command window that we will show you shortly you could ask whether a variable for example is keyword by using is keyword and the name of the variable but i'll show you a list of these uh keywords that you're not supposed to use for the name of your variables um at the very end for example one of the keywords is switch you cannot use switch because matlab uses that for a specific purpose and if you use a variable called switcher you can have an error message remember that names are case sensitive so if you have a variable called name uppercase name lowercase name and name beginning with uppercase character there are three different memory locations three different variables okay so be consistent as you write matlab programs we also recommend not to use those names that are assigned to functions within matlab and we'll have many functions to look at so for example we have functions for finding a cosine of an angle and that's called cos do not use cos for the name of a variable in your program because if you do so and you want to use the cosine of an angle in that program then that is not going to be recognized as the cosine function so we highly recommend that you avoid using names that are names of functions for your variables all right folks any questions so far so should you have any questions please uh raise your hand and if it's in the middle of my lecture or i can give you a chance to ask questions as i have been doing uh all along today all right so let's move on now to the next slide um can you uh go back a little please uh i've got a couple more things i got to write down thank you well all these are available on our course website okay uh yeah i have already posted this presentation earlier today uh actually midnight last night so if somebody wants to look at this ahead of our lecture they have it available to them and this is what we're going to be doing uh through the entire course of the semester all right so common types of variables that we can use for processing our data we could have data that has decimal numbers in it like 12.5 okay then we will be using a data type called double and double basically assigns a large memory to our data it has 64 bits and not only has 64 bits uh which we can um store data as large as plus and minus 10 to the power of -3 or 8 to plus and minus 10 to the power of 3 or 8. so we can store numbers really that large and then matlab would process that data up to 15 decimal places so it's going to be extremely accurate this way we can also have complex numbers where the complex numbers are numbers that have a real part and an imaginary part for example here this variable this variable called var has a real part which is one and an imaginary part which is also 1 but imaginary part always is shown with i multiplied by a number and since it is i only here it means that the number that is multiplied by i is one so then the real part is one and the imaginary part is also one all right now you could also have characters you know a letter for example a dollar sign you know a dot for processing those types of characters we use what is referred to as char data type and we have 16 bits of memory locations for that we could also have since we know arrays we know matlab treats data as arrays you can imagine that a name is nothing but a set of characters one after the other and therefore we could have character arrays and each of those characters in a name represent one of the elements of that array so in this case here we have a variable called comets and it contains this sentence this is a characteristic so these letters t h i s blanket space i s blanket space a blanket space and so on and so forth those are all elements of this array called comment the only difference between this array and the ones that we saw in the previous slides is that this array is a character array which means the content of those memory cells that you saw are all characters so if you want to know what type of variable you have look at the data type that you're going to be storing in that variable in that memory location and if you are storing a double data type then your variable is a double type and if you are storing characters in there then your variable is a character type how do you assign values to those memory locations that you give a name to well the easiest way is to use the assignment statement so the assignment statement has to be written this way that you write an expression and you assign that to this ver this variable called var so this equal sign here as you will see in matlab is not really what we know in mathematics this is called assignment operator assignment operator and what it does it processes the right side and then assigns the answer to this memory location to this barrier so arrays are constructed using brackets and semicolons and i'll show you some examples of that all of the elements of an array are listed in row order the values in each row are less listed from left to right and they are separated by blank spaces or commas the rows are separated by semicolon themselves and the number of elements in every row of an array must be the same so if row one has five numbers in it row two also has to have five numbers and row three also five numbers so all rows would have to have the same size the expression used to initialize the arrays that we mentioned up here this expression can include algebraic okay operations and they are all and all or portions of the previous defined arrays can also be used in these expressions so let's look at some examples take the first one a is assigned 3.5 3.4 sorry here and we put that inside square brackets so that's important b on the right side now is assigned an array that has four elements one two three four and then they are placed inside brackets c here has three elements also but they are placed inside bracket in a different form what separates the values here is no longer black blank in this example here what separates them are semicolon and semicolon basically ends each row so what this means is that the first row has only one number and that row ends because of the semicolon and then you go to the next row which happens to have only one number also here two and then the semicolon follows two and then the last row also has one number so this is basically a column array it's a column vector right so 1 underneath that 2 underneath that 3. so let's look at d here now d is a matrix is having two dimensions why because as you can see there are there is one row and semicolon and then the next row and on each row you have three numbers and now row values numbers uh on one row can be separated either were blank that you saw in b here but you can also have them separated by a comma okay all right now let's look at e here e is using a a previously defined array and a number 10.2 therefore a value which is 3.4 would be replacing here and e becomes collection of two values 3.4 and 10.2 how many columns do we have in variable e folks how many columns five in variable e we have five hmm well oh i thought you were talking about f no we were talking about e oh e is 2 e is 2 exactly why because we have two values on one row and these values are separated by a comma or a blank and represents two column within matrix e one row and two columns now f is b and a and they are placed on one row so one two three four is the first one that's b and then a follows which is 3.4 and then we'll have one row and five columns so remember values on a row represent columns and these columns can be separated from each other by a blank space as you saw in part b or by commas as you saw in part d or e or f rows themselves are separated from each other by semicolon okay all right so in order to initialize um a specific variable we can also use some shortcuts and i'd like to show you the first shortcut your expression could look like this one here a value we call it first and a colon another value we call it increment and colon and then last and what happens here is that the variable will be assigned the first value first and then we'll increment that by the size of the increment to get the next value and then keeps incrementing by the size of the increment and generating data until you get to the bounding value called last here so the colon this is called colon operator and it's a shortcut for creating really arrays of extraordinary size so in this example here x is assigned variable uh assigned 1 colon 2 colon 10. and we have left out the bracket when you're using the colon operator you don't have to put the co the bracket but you could put it in as a matter of practice and just be consistent but what this tells us is that x has the first element which is one and then the second element would be two added to one so that would be three and then the next element after that would be incrementing again by two so that's five and therefore we're going to get this array here 1 3 5 7 and 9. why does it stop at 9 because the next value 11 is greater than the bounding value which is 10 here so that's one way of initializing a variable by assigning values using colon operator naturally the increment can be negative or positive if it's negative the initial value has to be greater than the last value so the first value has to be greater than the last value because your increment is negative and it keeps reducing from initial value okay so this is another example that we are using the colon operator to define another variable called angles and what it does it really takes a value here an array and multiply it by pi you know pi right uh 3.14159 that number in mathematics it's represented by word p i or pi so what it does it really starts our first angle which is .01 and multiplies that by pi so that's the first number then increments point zero one by another point zero one because that increment is point zero one also so the next value would be point zero two multiplied by pi and then point 0 3 multiplied by pi and then .04 multiplied by pi all the way up to you until you reach to 1 times pi so it would be a very large array another way of defining an array is to use what we refer to as transpose operator transpose operator is nothing but this quotation as shown inside the parenthesis here and what it does it kind of swaps the rows and columns of an array so take a look at g here g is equal to one colon four what happened here if you're using colon operator what happened to the increment well remember if the increment is one you don't have to write in the increment so if the increment is missing matlab automatically assumes that that increment is one and so g is nothing but a row that contains one two three and four so f is also similar to g here is one two three four but instead of a row is now a call a column because of that apostrophe we are transposing that collection of data so one two three four that appears in a row now is transposed so becomes a column and now f is a column that has one two three four numbers in there what about this h here what do we have how many rows and columns do we have in array h anybody two rows and two columns close two columns is close is correct four rows and two columns sure four rows and two columns and that's because this is what happens it takes g here and transposes it so zero was row so transposing it becomes column one two three four and then it takes g again and transpose it for the next column and that's what you get so four columns four rows and two columns so that's another way of assigning values to your array names right another way of doing that is to use what is refer to uh function lin space lin space called linear space but the actual function name is lens space and this function here you could put three values in the argument initial final and how many values you want num so this lint space creates an array for you beginning with the initial ending with the final and containing num setup values so this one here for example linspace creates array x for you the values that are in there is the first one is one the last one is ten but it contains three values as you see here so the last number represents how many values you have in this set so if our initial value is 1 and our final value is 10 we have one additional numbers to make three values and what would that be folks equally a space 10 5.5 so the increment from 1 to 5.5 is 4.5 and from 5.5 to 10 is 4.5 so equally a space it's linearly a space all right three values now we have another function similar to linspace it's called logarithmic space logspace behaves exactly the same as linspace however it would look at the log of those values not the actual values that you see in the function so if i write something like this assigned to k log space of 1 comma three comma three how many numbers do we have in this set anybody three the last number argument is number of values so it's three it begins with one and it ends with three but remember this is log space function so it begins with the log of a number that is equal to one log of which number is equal to one remember this is log base ten log of ten is one log of hundred is two log of a thousand is three log of ten thousand is four and so on and four so forth so then it begins with one which is ten here because this is what number has a log of one is ten and it ends with log of a num a log of a number that is equal to 3 which is a thousand and then it has a number in between them to make up three for us again logarithmically spaced and that is this here 10 hundred and thousand so we can use all these functions there are some newer functions there are two zeros and ones and you can write them in different form for example if you say zeros five it gives you an array containing fi five by five locations with zeros in there in all those locations when you say zero two comma three it will give you a matrix of two rows and three columns and the content of each of those elements or cells would be equal to zero you could do the same thing with ones so if i say ones two comma three you have a matrix of two rows and three columns and each value within those memory cells or each element of the array would be equal to one okay and finally how do you initialize values on the input keys so one way is to assign values to our variables that's how you initialize it another way of initializing the content of a variable or the values within a variable is to have the user enter a num those numbers for you okay so this is called initializing using the keyboard input for this purpose we use a function called input and what this function does it waits it displays a prompt to the screen you decide what that prompt is so it displays it to the screen and then waits for the user to enter something with the input it could be numeric it could be character or anything so this example for here input inside the parentheses is your prompt you say enter an input value okay so then this prompt here enter an input value would be displayed to the screen and program waits it waits for the user to enter a value and then as soon as that value is entered it picks up that value and puts it in the memory location assigned to my underscore val so it waits and now you can enter 4.8 now the value of your variable which is my underscore val is 4.8 you may have something like this here it says enter data so enter data is going to be displayed and it's waiting for you to type in something so if you type in this here bracket 1 3 6 10 bracket close and then press enter then the value of very values within varia variable in1 would be these this set of numbers you could also type in something like this you could say enter data and then after that prompt put a comma and then s what this does is going to consider the input as a string of characters and therefore it's used for reading in for the user entering names and characters and addresses and so on so then this would be displayed enter data the user can type in diablo valley college and all these characters within diablo valley college including the blanks between the words would be then assigned to the variable called in2 okay all right so let's just stop here give you a view of some of the keywords break otherwise case r4 catch and so on and so forth so in this uh slide you have basically um some keywords listed here okay and if you can just remember those um those are pretty much it for now okay all right any questions before we switch to another uh phase of our lecture today any questions at all all right one so for the uh sorry never mind okay i'm going to give you more examples now in uh in using uh matlab so hopefully if you have more uh questions we i can answer it there so the next thing to do is um to introduce matlab environment to you and hopefully have you uh work on today's assignment which is writing your first matlab program you still don't know how to write matlab programs i've given you the program but i want you to take that as a practice and go through the assignment number one and finish writing that and running executing that and having matlab generate some data for you so that's what what i'm going to show you uh for the rest of the remaining time the first thing is that you are all given access to our computers in the engineering department that contain matlab software okay and i'm going to show you how you do that matlab software is created by mathworks m-a-t-h-w-o-r-k-s by mathworks and it is really based on written based on c programming c plus plus and c programming languages so itself therefore has some of the capabilities of that language as well matlab is a pretty expensive package it's uh in the entire package without any additions that they call they call them toolboxes it costs about four thousand dollars per copy and then if you add those additional programs called uh toolboxes that do more a specialized uh analysis for us such as simulations for example or image processing and so on and so forth then the cost keeps adding up the good news is that matt works although it's very expensive for us for example to buy it and install it on our computer or somebody in a company buy it or a company buys it they know that we have a student their students have limited budget and therefore they are selling that four thousand dollar package uh at hundred dollars cost to you as a student so you purchase the commercial uh version it's not a rundown version it's exactly the same version as the four thousand dollar uh version it's practically the same thing not only that but they also give you some of those toolboxes that i mentioned for free you don't have to buy this but i'm just saying that that's an option all of you specifically people going into mechanical civil bioengineering you know and chemically you'll be using matlab for probably the rest of your life and some people purchase it now because it helps with other courses uh specifically and with your classes as you transfer and eventually as a profession so if you like to have it you go to mathworks.com have written this on today's announcement that says remote access if you look at top of our homepage there are two announcements one is what we're going to do today and the other one says remote access and at the bottom of that document that you can open uh it shows you where to go to purchase anyways but we have it here in the department and you can have access to i'm going to walk you through the process of accessing the accessing the uh a computer in our matlab environment so let me just simply share my screen here someone would use this one okay so we have a blanket screen here uh the url that you're going to be using it's listed also on the announcement today is letter i d m so idm dot dvc dot edu idm dot dvc.edu you press enter here okay so it brings you here i am directly i have directly come here without logging on because i was using the package earlier this morning but when you come in it wants you to enter your username and your password and your username is your insight email address and your password is your inside password once you enter on the upper right corner shows your name initial of your first name last name sk for me and then it gives you this option here apps this is applications you click on applications and you go down the list it gives you this application called etlab dash01 so this application connects you to one of the computers in the engineering department computer labs if you click on it a message comes up it says open vmware horizon client 32-bit just go ahead and open that just say open and after waiting a few seconds it tries to do its job of connecting you to one of the computers it looks at what computer is available and then grabs that and once it grabs it then it's going to show you the desktop of the computer that you're going to be given access to so this is the desktop of one of the computers that is now assigned to me and as you can see this desktop shows all software available that you can run on that computer and you'll be running that naturally remotely from your computer directly okay so i think we can see oh there is no need to come to dvc for that purpose you remotely do this now this message comes on and it says hey after 30 minutes of inactivity you will be disconnected then after an additional 50 minutes your session is logged off now please take this notice here with a grain of salt if you leave your system uh standing by itself after about five minutes or so you of inactivity you would be disconnected from that computer you're still logged on to our uh uh vmw to our vmware software but you're not connected to that computer anymore and then after about 10-15 minutes past that then you'll be completely logged off and you lose the connection all together and you have to start all over okay did anybody somebody had a question here you can't see your window screen nothing is connected here it's sharing your laptop screen right now oh wow so let me stop sharing here and then go back and share again thank you okay can you see now the desktop of the computer i'm assigned to yeah okay thank you for letting me know okay so it says it may come up depending on the size of your screen it may say hey if you change your resolution you're going to view the desktop better as you can see i have a very small laptop here and the icons show up relatively large i cannot set my resolution to a high resolution that it's recommending so i just leave it as is here and just say okay all right so now one of the applications is this here matlab as you can see we have release 2022a that's the latest one that we have on our computer so we double click to begin as you double click matlab is loaded slowly of course and uh we're going to see matlab environment shortly uh do you all see matlab a screen now yes okay great yes i just i'm checking out the first thing to remember that when matlab opens up there are three windows that are given to you the first window which is highlighted in uh with the banner called command window the lower right is command window this is the main channel of communication with matlab you could write something here and matlab takes it in and analyze it and displays the answer back on the same screen so command window is very critical the next window is the middle left window called current folder window and i'm clicking on that so it highlights here what it does it really shows you all files that you have created in the current directory now the what is the current directory is shown right here it says on c drive you go to a folder called users to a folder which has my name and then the folder called documents and the folder called matlab so what is in this directory here in this folder is shown in the current directory so if i create a file called test then i should see a name here test dot m and m is really the extension for matlab files the next window is this window here is called workspace workspace shows all variables and the type of data that they represent and more information about that for example the size of them or what values are restored in them okay so so far we have not done anything here at all now at the very top you see three tabs home plot apps we'll be working with home under home you have new script new live script new for file open a file and there are a number of other options variables code environment and resources you can use matlab in two forms either interactive which means you stay in the command window and communicate with matlab and get the answers you want or you can write a program file the advantage of the second method writing a program file which we call it a script is that these scripts contains all the instructions that you need to give to matlab and then matlab can process those one after the other if you do that in the command window you cannot go back and run those instructions all over again you have to redo them one more time and then one more time after that the advantage of a script is that you've already written all those instructions once and you can ask to be to be executed as many times as you want and that's why we're going to be using win matlab in the programmers mode in creating a script mode rather than interactive mode so but let me show you in the interactive mode you could say for example four plus five and then press enter what happened it says what the answer is a and s is for answer so since i did not assign any variable to that operation it automatically assigns it to a variable called ans now if you look at the workspace on the lower left you see a and s is right there do you folks see that ans and it says there is a number inside that variable and that number is nine here all right let me see if i can move okay all right so let me go ahead and do something else uh seven divided by two sorry seven divided by two it says 3.5 now a n s is assigned this new value what happens to the old one nine it disappears because you're overriding the content of this memory called ans and now if you look at the workspace lower left corner you would see that the content of that is 3.5 so that's why it's a good idea to assign to each operation a specific value so you could trace them back so you could say a assign to them uh maybe one and two and four okay and press enter so now a is created on the lower left corner and it has three numbers in it and i can do this with other things as well something to remember here when you type a equal to 1 2 4 it echoed back the value of i to the screen now this is typically very extra junk here do we really need this i already know that a is one two three four why should i occupy the command window by these extra pieces of information the good news is that you can suppress this the way you suppress it is simply by putting a semicolon at the end so you could say b is equal to uh one increment of one two six okay and then you put a semicolon now that does not echo back the value of a of b but shows on the workspace that we have one two three four five six uh the content of b so placing semicolon at the end of your statement suppress echoing values to the screen and it makes it easier really to follow all right another thing what if i want to go back to a equals 1 2 4 do i have to type it in again the answer is no you could use the arrow keys on your keyboard the up and down arrow keys if i press on my up arrow key all the things that i've done in the past show up here so then i can naturally go up to any of them through this one for example or seven divided by two and once i go to the one that i like i can see that it shows up on my command window so if i can't want to come back and make modifications to it i can or if i want to put a semicolon at the end i can okay all right another thing to remember is that when these pieces of information were echoed to their screen they really took up quite a bit of a space you see there is a blank line right here there is another blank line here and another blank line after that so can we have things echoed but kind of in a compact form yes what you do is on the command line or in your script you type in format space compact so format compacts allows echoing of information but not with all those blank lines so let's bring back a here and i'm going to go and remove the semicolon and press enter now as you can see a is echoed here with its value but then this blanket space between definition of a and a equal and the blank space between a and the numbers they are all disappear so format compact does that for you so while you can do all kinds of things here in matlab um as i said this interactive mode is really not very attractive for programmers for writing programs and analyzing you know designs and things like that therefore we'll be using the so-called script or programmers mode the first thing to do is to create to tell matlab that you're creating a program or a script so you go to newest script not to live script so don't go to the icon next to a new live just go to newest screen script and click on that alternatively you can also go to new and look at this drop down menu and ask for a script so two ways the icon is available here so we just simply click on that what happened did you see something happening yes this new editor opened up this new window opened up where is my command window it's down here if you click on it it activates or i can come back here to this editor excuse me now so the editor is available now it allows you to create a matlab uh script or matlab file and you can write anything that you write on the command window right here so for example you can write a script that would clear the command window for you so you could say clc so anything that is on the command window when this program runs is cleaned up first all right i can also ask for the command window to show the data that i'm going to be generating by this script in a compact form so i can say then format space compact all right so let's say we're going to define some variables here and we like the value of those variables to be given by the user so x assign inputs remember how we get input from the user use input value and we ask the user to enter some numbers wait um please go over the clc again that clears the command window so whatever junk we have on the command window is cleaned up uh and then the data for this program would be placed on a clear wind command window so that way we can see everything clearly whether it's error message or data related to our program so anything before that is going to be cleaned up we'll talk about this in detail i'm just trying to show you if you write a script what happens so the process is more important for us at this stage all right let's say um we like to display the value of x eventually to the screen and i say x here so the value of the x would be displayed so let's say i've created this script the first thing to do is to go and save this okay so when you go to save it says give me a name for this let's i'm going to call this my first program pay attention that to this name first it's going to assign a dot m and we just say save now pay attention to the current folder can you all see current folder not containing a program called first dot m do you folks see that yeah great so now we're going to run this execute have matlab execute these so i'm going to go and use this icon here run icon and what this run icon does it executes these statements one after the other and shows me the result if any on the command window so we go and run so do you see on the command window it says enter some numbers so let me just enter some numbers 2 4 1 minus 6 okay and press enter so command window is kind of not showing everything if i scroll up a little bit here so after i enter 2 4 1 6 then i had x here on my script right so on command window then it displays x equals and displays the value of x for us so what happens if i had an error here let's create an error remove this semi apostrophe here okay and i'm going to run this do i have to save it again no the next time that you run except for the very first time that you had to save your script any other time that you run it saves your changes and then it runs it so it has an automatic saving in it so if i go to run oops if you look at the command window there is an error message it says that it was running first file and it says file first dot m line three line three it says column nine uh don't pay attention so much to that column location it's sometimes not the case but i'll show you what so it says on line three there is an error and then it tells you what that error is it says character vector is not terminated properly so character vectors what are they they are the things that we place inside apostrophes and since i have an opening apostrophe here it assumes that hey we are creating a character vector and then there is no apostrophe to close it so then that's what we do we come back and add the apostrophe here and run it again and that says give me some numbers if you want the previous set you use your arrow keys up arrow in this case and i go and pick my num last number and press enter and then x is displayed for me okay so error messages are very straightforward and gives you sufficient information to go back and modify your script now displaying data such as what i did here like x is not very useful maybe this set of numbers represent a specific event or a specific set of events maybe they are indices of various products that you are recording and therefore when you say x print x for me you're not giving it any label at all however you could give label by using a function called display and just in a simple form of that you could just simply display here if these numbers represent let's say markings on a tape you could say markings on a tape are and then you show what they are and leave a blank and then after that you want to display the value of x because x are those markings so then you say x here and enter now let's run this again now it says again give me some numbers you could enter the numbers and now let's see what happens it says markings on a tape are 1 2 4 and -6 so this is a more useful uh way of displaying information really rather than just leaving a variable name there without any description okay so this is how you create your first script now what you're going to do once you create this first script while you're still connected right we are still connected to the computer um in the lab you want to go and send this or upload it to your assignment while you're still connected because when you disconnect you're going to lose all that data all that file all the files that you create would be lost when you're disconnected therefore while you're connected to the computer you can either email that file to yourself or you could upload it to your folder to your assignment folder so let's say in this case here we're going to go to our chrome [Music] browser i'm going to connect to my um course uh the best is to go to dvc.edu go to canvas here www.dbc okay so dbc comes up we go to canvas we log on we go to our courses 136 52 66 go and look at my assignments i should be under student view so i open my assignments assignment one and it says a start assignment say i start assignment so for a start assignment you'd be doing file upload no text entry so file upload and if you look at your screen further down here it allows you to upload file so you say upload file and then it says what is it upload file choose file so it can you see the directory that is opening up here there's the newest screen where i have to find my file folks do you see this okay so we go to our documents go to matlab and here is my file first open it and it's already showing up there and you submit to okay so while you're connected you need to do that you can also email a copy to yourself if you want to now before finishing up here though since you're going to be sending me a file how would i know whether this file worked or not so then you show me the sample of the operations on the command window how do i show that well you copy paste it to the bottom of the file so you come to the command window you highlight that portion related to your output you copy it and then you come back to the bottom of the file and you paste it there but these are not really part of your actual program right these are the output of the program so the best thing is then to make these only comments comments are parts that would be ignored by matlab so you could then therefore highlight all of these here and come to this percentage sign and click on it and percentage sign makes that portion comment and that's why it's in green so what do we use comments for well i use comments up here to show that who created this file so i say percentage my name here and i give it more information this is my first dot m file and i can say this is my assignment one you know and so on and so forth so all of these are ignored the only thing that is going to be executed is clc format input for x display this title and display the value of x that's all it does so then i can run this again and see nothing happens except the same process i can enter 0 1 0 2 and enter now if you look at the command window and you scroll all the way up the previous output which was this one is no longer there why because when i ran the program clc cleared what cleared the command window for me so i have all these new data there you may ask can i also clear this workspace so these data be for example i don't need it in this why do i have to have it yes you could do that after clc you could place a comma and then type clear c l r clear clears your workspace for you so if i run this for example and i give it the numbers that i want look on the workspace you only have one variable x and all these previous one a and b that were not really relevant to us were in there okay so what i'm asking you to do in today's assignment is very simple let me just stop here oh one thing that i'd like to mention here folks when you finish your work with matlab and you close it and you're done here close the banner here say yes you like to disconnect you're not done yet what you should really go we're not able to see a screen professor i'm sorry we're not able to see your screen it's natural thank you i'm going to show you my screen okay so after you close matlab and you close the vm vmware banner make sure that you go to your browser on this page here do you folks see all this page make sure that you yes yeah you can see it yeah then we go here to our name and we sign out it's important that you sign up because if you don't sign out next time that you come to access the program says access denied it's because it's assuming that you're still logged on somewhere therefore you have to sign out each time don't forget that if you forget this to happen what you need to do is you need to go to your browser again if you get that error message go back to the browser and click on your name and sign out and then clear your browser history and it starts all over again so remember that this is some of the problems people may run into and i don't want you to run into such problems so let's go back to finally look at our excuse me look at our oh boy so engineering this is our class here so when you finished going to the assignment um let me just bring up the assignment here assignment one so all i'm asking you to do in this assignment first of all this assignment contains a description of what we've done today and i'll show you everything here just for reference this is your script window and then this program is given to you from program one percentage you should type all of that all the way to end of file do not copy and paste this why because there are special characters here that when you copy paste it matlab is going to generate errors sometimes those characters are not visible so then you'll be dealing with errors that you don't know what to do so start typing on your script window from percentage program all these percentages and then clear and clc and all these data here so once you get to the bottom and you type in end of file then you run your program as you run the program there would be some outputs you copy paste those outputs as i just did from the command window to the bottom of this file and then you save the file and upload that file for program one therefore when you're ready to come here and say a start assignment do this while you're connected to the computer in our engineering computer labs as i was showing you and while you have your matlab open still open so just send that in that way you're sure that you have done this or you could do another thing you could email that file matlab file to yourself go back to your original browser not connect it to uh computer lab any longer and then you can upload your file that way i prefer this method because i will have a hard copy of my own also of each assignment for later references in any case you could do a combination okay folks this actually concludes our discussion for today do you have any questions for me um professor yes so i tried to open it but it doesn't allow me to open the microphone it doesn't allow me to link to the computer okay what does it say anything so i click on etlab 01 and then it says launching but i waited for like almost 20 minutes but it doesn't do anything what kind of computer do you have i'm using is it the chrome yeah i'm using chrome no chromebook uh you know doesn't work you have to have an actual computer and apple uh you know macbook or a pc matlab is extremely large and it really does not load on you know ipad or you know oh no i'm using a laptop like windows laptop you're using a windows laptop yeah yeah but i'm using like a chrome website okay why don't you stay behind i'm going to stop our discussion here and i can't