In the second tutorial video on Octave, I'd like to start to tell you how to move data around in Octave. So, if you have data from machine learning problem, how you load that data into Octave? How do you put it into matrix? How do you manipulate these matrices? How do you save the results? how do you move data around and operate with data? Here's my Octave, window as before. picking up from where we left off in the last video. If I type A, that's the matrix that we generate, right, with this command equals 1, 2, 3, 4, 5, 6 and the this is a 3 by 2 matrix. The size command in Octave lets you tells you what is the size of the matrix, so size A returns 3, 2, it turns out the size command itself is actually returning a 1 by 2 matrix. So you can actually set SZ equals size of A and SZ is now a 1 by 2 matrix where the first element of this is 3 and the second element of this is 2. So you can just type size of SZ SZ as a 1 by 2 matrix whose two elements contain the dimensions of the matrix A. You can also type size(A,1) to give you back the first dimension of A, of, size of the first dimension of A, so that's the number of rows and size(A,2) to give you back 2 which is the number of columns in the matrix A. If you have a vector V, so let's say V equals 1, 2, 3, 4, and you type length V, what this does is it gives you the sides of the longest dimension. So you can also type length A and because A is a 3 by 2 matrix, the longer dimension is of size 3, so this should printout 3. But usually we apply length only to vectors, so your length 1, 2, 3, 4, 5 rather than apply length to matrices, because that's, that's a little more confusing. Now, let's look at how to load data and, find data on a file system. when we start up Octave, we're usually, we're often in a path that is near the location of where the Octave program is. So the pwd command shows the current directory or the current path that Octave is in. So right now, we're in this somewhat, maybe somewhat obscure directory, the cd command that stands for change directory, so I can go to c:\User\ang\Desktop and now in my desktop. And if I type ls ls is a type that comes from a Unix for a Linux command, but ls will list the directories on my desktop. And so, you know, these are the files that are on my desktop right now. In fact, on my desktop are two files, featuresX and priceY, that's maybe come from a machine learning problem were going to solve. So, here's my desktop, here's featuresX. And featuresX is this window, excuse me, is this file with two columns of data. This is actually my housing prices data, so I think you know, I think I have 47 rows in this data sets and so the first house had size 2104 square feet, has three bedrooms, second house has 1600 square feet, has three bedrooms and so on and priceY is this file that has the prices of the data in my training set. So [SOUND] featuresX and priceY are just text files with my data. How do I load this data into Octave? Well, I just, type load featuresX.dat and if I do that and load the featuresX X, I can load priceY.dat. And, by the way, there are multiple ways to do this, this command, if you put featuresX.dat in strings and load it like so. This is oops, typo there. This is a equivalent command so you can you know, but this way, I'm, I'm just putting the file name of the string in the file name in, in a string and in Octave use single quotes to you know, to represent strings like so. So that's a string, and I can load the file whose name is given by that string. Now, the who command now shows me what variables I have in my Octave workspace, so who shows me what are the variables that Octaves has in memory currently, featuresX and priceY are among them, as well as the variables that, you know, we created earlier in this session. So I can type featuresX to display featuresX and there's my data. And I can type size featuresX and that's my 47 by 2 matrix. And sum of the size priceY, that gives me my 47 by 1 vector for, this is a 47-dimensional vector, this tall column vector that has all the pricesY in my training set. Now, the who function shows you what are the variables that in the current workspace. There's also the whos variable that gives you the detail view, and so, this also, with an S at the end, this also lists my variables, except that it now lists the sizes as well. So A is a 3 by 2 matrix and featuresX is a 47 by 2 matrix price, priceY is a 47 by 1 matrix, meaning this is just a vector and it shows, you know, how many bites of memory it's taking up as well as what type of data this is. Double means double precision, 48 points, so that just means these are real values of floating point numbers. Now, if you want to get rid of a variable, you can use the clear command. So clear featuresX and type whos again, you notice that the featuresX variable has now disappeared. And how do we save data? Let's see, let's take the variable V and set it to priceY(1:10), this sets V to be the first ten elements of of the vector Y. So let's type who or whose, whereas Y was a 47 by 1 vector. V is now 10 by 1, because Vprice equals priceY(1:10), this sets into the, just the first ten elements of Y. Let's say I want to save this to data, to disc. The command, save hello.matv, this will save the variable V into a file called hello.mat. So let's do that. And, now, a file has appeared on my desktop, you know, called hello, hello.mat I happened to have MATLAB installed in this Windows, which is why, you know, this this icon looks like this, because Windows is recognizing this is a MATLAB file. But don't worry about it if this file looks like it has a different icon on your machine. And let's say I clear all my variables, if I, if you type clear without anything, then this actually deletes all the variables on your workspace. so I type whos, there's now nothing left in my workspace. And if I load hello.mat, I can now load back my variable V, which is my the, the data that I previously saved into the hello.mat file. So, hello.mat or what, what we did just now, the save hello.mat to V, this saves the data in the binary format in a somewhat more compressed binary format. So that if V is a lot of data, this, you know, will be somewhat more compressed and will take up less of the space. And if you want to save your data in a human-readable format, then you type save hello.text, the variable V and then -ascii. So this will save it. As text, or as ASCII formatted text. And now, once I've done that, I have this file, hello.txt is just appeared on my desktop. And if I open this up, you see that this is a text file with my, with my data saved away. So that's how you load and save data. Now, let's talk a bit about how to manipulate data. Let's set A equal to that matrix again. So there's my 3 by 2 matrix. Let's start by indexing, so if I type A(3,2), this indexes into the three comma two element of the matrix A. So this is what a, this is, you know, normally we would write this as A subscript 3, 2 or A subscript, you know, 3, 2. And so, that's the element in the third row and second column of A, which is the element 6. And I can also type A(2, ): to fetch everything in the second row. So the colon means every element along that row or column. So, A(2, ): is this second row of A. Right? And similarly, if I do A(:, 2), then this means get everything in the second column of A. So, this gives me 2, 4, 6 by this means of A, everything comma second column, so this is my second column of A which is 2, 4, 6. Now, you can also use somewhat most sophisticated indexing operations. So, so, I'll just quickly show you an example. You, you do this maybe less often, but let me do A([1 3], ),: this means, get all the elements of A, whose first index is 1 or 3. This means get everything from the first and third rows of A and from all columns. So this was the matrix A, and so A([1 3], ): means get everything from the first row and from the second row and, and from the third row. And colon means, you know, I want both the first and the second columns and so this gives me this 1, 2, 5, 6. Although you, you, use these sorts of more sophisticated indexing operations, maybe somewhat less often. To show you what else we can do. Here's the A matrix, and let's, this was a colon comma to give me the second column. And you can also use this to do assignments. So I can take the second column of A and assign that to ten, eleven, twelve. And if I do that, I'm now, you know, taking the second column with A and I'm assigning this column vector 10, 11, 12 to it. So now A is this matrix that's 1, 3, 5, and the second column has been replaced by 10, 11, 12. And here's another operation, it's A let's set A, that's A to be equal to A comma, 100, 101, 102, like so, and, what this will do, is it appends another column n vector to the right. So now oops, I think I made a mistake. Should I put semicolons there? And now, A is equal to this. Okay? I hope that makes sense. So this 100, 101, 102, this is a column vector. And what we did was, we said AA take A and set it to the original definition and then we put that column vector to the right and so we ended up taking the matrix A and which was this, these six elements on the left. So we took the matrix A and we appended another column vector to the right, which is now Y, now A is a 3 by 3 matrix that looks like that. And finally, when we click that I sometimes use do A and then just a colon like so, this is a somewhat special case syntax. what this means is that, puts all elements of A into a single column vector and this gives me a 9 by 1 vector that just has all the algorithms of A [INAUDIBLE] together. just, a couple more examples. I can also, let's see. Let's say I set A to be equal to 1, 2, 3, 4, 5, 6, again. And, let's see I said B to be equal to 11, 12, 13, 14, 15, 16. I can create a new matrix C as [A B] and this just means, so here's my matrix A, here's my matrix B, and off a set C to be equal to AB. What I'm doing is I'm taking these two matrices and just concatenating them onto each other. And so the left, [INAUDIBLE] matrix A on the left. And I have the matrix B on the right. And that's how I form this, you know? this matrix C, by putting them together. I can also do C = [A; B]. The semi colon notation means that means, it, means go put the next thing at the bottom. So we do sequence A sem colons B it also puts the matrices A and B together, except that it now puts them on top of each other, so now you have A on top and B at the bottom and C here, is now a 6 by 2 matrix. So, so just saying, the semi colon thing usually means you go to the next line. So C is comprised by A and then go to the bottom of that and then put B, the bottom and by the way, this AB is the same as A, B and so, you know, either of these gives you the same result. So, with that, hopefully you now know how to construct matrices and hopefully this starts to show you some of the commands that you can use to quickly put together matrices and take matrices and, you know, slam them together to form big, bigger matrices. And with just a few lines of code, octave is very convenient in terms of how quickly we can assemble complex matrices and move data around. So that's it for moving data around, in the next video we'll start talk about how to actually do complex computations on this, on, on, on our data. So hopefully that gives you a sense of how, with just a few commands, you can very quickly move data around in Octave. You know, load and save vectors and matrices or load and save data put together matrices create bigger matrices indexed into or select specific elements of the matrices. I know I went through a lot of commands, so I think the best thing for you to do is afterwards to look at the transcript of the things I was typing, you know, look at the, look at the coursework sign and download the transcript of the session from there. And look for the transcript and type some of those commands into Octave yourself, so that you can start to play with these commands and get it to work. And obviously, you know, there's no point at all to try to memorize all these commands, it's just, but what you should do is hopefully from this video you have gotten a sense of the sorts of things you can do, so that when, later on, when you're trying to program a learning algorithms system yourself. If you are trying to find a specific amount that maybe you think Octave can do because you think you might see it here you should refer to the, to the transcript of the session and look through that in order to find the commands you want to use. So, that's it for moving data around and in the next video, what I'd l like to do is start to tell you how to actually do complex computations on our data and how to compute some data and how to actually start to implement learning algorithms.