0% found this document useful (0 votes)
6 views23 pages

Create MATLAB Variables That Contain Multiple Elements: 4. Vectors and Matrices

The document provides an overview of creating and manipulating arrays in MATLAB, including tasks for manually entering arrays, creating evenly spaced vectors, and using functions to create arrays. It also covers array indexing, modification, and calculations, emphasizing the importance of understanding how to extract and modify values using indices. Additionally, it discusses calling functions with multiple outputs.

Uploaded by

tumambingaleah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views23 pages

Create MATLAB Variables That Contain Multiple Elements: 4. Vectors and Matrices

The document provides an overview of creating and manipulating arrays in MATLAB, including tasks for manually entering arrays, creating evenly spaced vectors, and using functions to create arrays. It also covers array indexing, modification, and calculations, emphasizing the importance of understanding how to extract and modify values using indices. Additionally, it discusses calling functions with multiple outputs.

Uploaded by

tumambingaleah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

4.

Vectors and Matrices ​


​ Create MATLAB variables that contain multiple elements

4.1 Manually Enter Arrays


Task 1​

Task 2
Task 3
Task 4

Task 5
Task 6

Task 7
Further practice

4.2 Create Evenly Spaced Vectors

Task 1
Task 2

Task 3
Task 4

Task 5
Task 6

Task 7
Further practice

4.3 Create Arrays with Functions


Task 1
Task 2

Task 3
Further practice

5. Array Indexing and Modification ​


Use indexing to extract and modify rows, columns, and elements of MATLAB arrays.

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

5.4 Change Values in Arrays


Task 1
Task 2

Task 3
Further practice

6. Array Calculations ​
Perform calculations on entire arrays at once.

6.1 Perform Array Operations on Vectors


Task 1
Task 2

Task 3
Task 4

Task 5
Task 6

Further practice
7. Function Calls ​
Call functions with multiple outputs.

7.1 Request Multiple Outputs in Function Calls


Task 1

Task 2
Task 3

Further practice

You might also like