Cell arrays are used to hold variables of different types or matrices of different sizes in MATLAB.
- [Narrator] Often, if we're working with complicated data sets, we want to be able to associate different data types, like say, vectors and strings together in a single construct. And, MATLAB allows us to do that with cell arrays. I found these really, really useful in my work so I wanted to show them to you here. Let's go ahead and clear the screen and I'm going to clear the workspace while we're at it. Here we go. So you can think of a cell array like a matrix. But, each element in that matrix can be a different data type. So, let's just go ahead and create one to see how it works.
I'm going to call it, my cell; and instead of creating it with parentheses or square brackets, we're going to create this with curly brackets. So I'm going to open and close those. And, for the first element in our cell array I'm going to create a vector. So let's create a vector of one, two , three and then just like when creating a matrix I'll do a space, and let's add another matrix here in our first row. But, I'm going to make this one a different size. So I'm going to call it four, five, six, and seven. So we'll have a four element. And then, let's say, in the second row, so I'll separate those with a semicolon we want to have some strings that identify these different vectors.
So I'll call this here, v1 and in the second column, we'll just say v2. Now, if I hit enter, we see that it's created a two by two cell array and in column one we have a one by three vector of doubles and in column two we have a one by four vector of doubles and then we see our strings down here, v1 and v2. And then, it's easy to access this data. Let's say we wanted to grab the vector associated with v2. We can say, my v2 and we'll grab it from my cell.
And again, we just access it with the curly braces. So we want row one column two. And we can see it returns for five, six, seven. These cell arrays can also be multi dimensional. You could have a three dimensional array for complex data. Even four, fifth dimensional arrays on up. So if you're ever working with complicated data sets keep these in mind.
- Creating MATLAB variables
- Working with matrix and scalar operations
- Using if statements and loops
- Creating functions
- Importing data
- Building basic plots and 3D plots
- Working with images
- Creating Simulink models