0% found this document useful (0 votes)
25 views2 pages

Practice Exercises Arrays: Instructions

The document provides instructions and problems for practicing array operations in MATLAB using pre-loaded arrays called "vector" and "matrix". Problem 1 involves indexing and extracting subsets from the 1D array "vector". Problem 2 does the same for the 2D array "matrix". Problem 3 involves using relational operators like > and < to evaluate conditions on the array elements and explain the results.

Uploaded by

Drake Ramoray
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)
25 views2 pages

Practice Exercises Arrays: Instructions

The document provides instructions and problems for practicing array operations in MATLAB using pre-loaded arrays called "vector" and "matrix". Problem 1 involves indexing and extracting subsets from the 1D array "vector". Problem 2 does the same for the 2D array "matrix". Problem 3 involves using relational operators like > and < to evaluate conditions on the array elements and explain the results.

Uploaded by

Drake Ramoray
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/ 2

Practice Exercises Arrays

Instructions:
Download the Array.mat file and save it in your current MATLAB directory. At the command
prompt, type >> load Array. Look in your workspace window. You should see a 1-d array
called vector (1x12), and a 2-d array called matrix (10x5).

All of these problems refer to the arrays vector and matrix downloaded from the Array.mat file.

Don’t change the values in vector or matrix unless prompted. If you do inadvertently change
them, just re-run the command >> load Array to recover the original arrays.

Problem 1: 1-d (vector) Array Indexing

Execute the following command first so you know what vector looks like.
>> vector

a) Give a single MATLAB command that will pull out entries 5, 6, 7, 8, 9 out of the 1-d array,
vector and put them in another vector called vectorA. Show both your command and the
results here:

b) Give a single MATLAB command that will pull out entries 3, 9, and 11 out of the 1-d array,
vector and put them in another vector called vectorB. Show both your command and the
results here:

c) Give a single MATLAB command that will overwrite the 3rd entry in vectorB with a value of
12. Show both your command and the results here:

Problem 2: 2-d (matrix) Indexing

Execute the following command first so you know what matrix looks like.
>> matrix

a) Give a single MATLAB command that will pull out rows 5, 6, and 7 out of the 2-d array,
matrix and put them in another matrix called matrixA. Show both your command and the
results here:
b) Give a single MATLAB command that will pull out columns 2, 3, and 4 out of the 2-d
array, matrix and put them in another matrix called matrixB. Show both your command
and the results here:

c) Give a single MATLAB command that will replace the values in rows 1 & 2 and columns 2
& 3 of matrixB with the following values:

Show both your command and the results here:

Problem 3: Arrays, Relational Operators, and Useful functions (sum and find)
This problem refers to the array vector loaded from the Array.mat file. Again, don’t overwrite
the values in the array vector. If you do, re-load Array.mat. For each of these commands,
show the result and explain the result in words.

(a) vector > 0

(b) vector(3:10) > 0

(c) matrix < 3

(d) 0 < matrix & matrix < 2

(e) matrix(1:3,2:4) > 2

You might also like