Create MATLAB Variables That Contain Multiple Elements: 4. Vectors and Matrices
Create MATLAB Variables That Contain Multiple Elements: 4. Vectors and Matrices
Task 2
Task 3
Task 4
Task 5
Task 6
Task 7
Further practice
Task 1
Task 2
Task 3
Task 4
Task 5
Task 6
Task 7
Further practice
Task 3
Further practice
5.1 Indexing
Every variable in MATLAB is an array. So to program in MATLAB, you'll need to
know how to work with arrays.
Referring to elements in an array is the first step. This is called indexing. Indexing is
how you extract and modify values in arrays. The position of a value inside any array
is called its index. You can use the index to extract particular values. For example, if
you want the third element of the vector x, you type x(3). If you know the position of
an element, you can also change the value. Here we're changing the value at the
third index to 1.
You can also extract a range of values by using a colon with the first and last indices
of the range. If you want to extract elements from a matrix, well, specify two indices
instead. The first index is the row number and the second is the column. It's pretty
common that you want to extract a whole row or a whole column from a matrix.
When you use a colon on its own as an index, it stands for all, as in all the rows or all
the columns. Here, we're extracting the first row and all the columns. And in this
case, we're extracting all the rows of the third column.
There's a lot more you can do with indexing, but for now, remember that matrix
indexing is row,column and vectors only need one index.
5.2 Index into Arrays
Task 1
Task 2
Task 3
Further practice
5.3 Extract Multiple Elements
Task 1
Task 2
Task 3
Task 4
Further practice
Task 3
Further practice
6. Array Calculations
Perform calculations on entire arrays at once.
Task 3
Task 4
Task 5
Task 6
Further practice
7. Function Calls
Call functions with multiple outputs.
Task 2
Task 3
Further practice