0
0
MATLABdata~10 mins

Special matrices (zeros, ones, eye, rand) in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a 3x3 matrix of zeros.

MATLAB
A = [1](3, 3);
Drag options to blanks, or click blank then click option'
Arand
Bones
Czeros
Deye
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ones' instead of 'zeros' will create a matrix filled with ones.
Using 'eye' creates an identity matrix, not zeros.
2fill in blank
medium

Complete the code to create a 4x4 identity matrix.

MATLAB
I = [1](4);
Drag options to blanks, or click blank then click option'
Aones
Beye
Czeros
Drand
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ones' creates a matrix full of ones, not an identity matrix.
Using 'zeros' creates a matrix full of zeros.
3fill in blank
hard

Fix the error in the code to create a 2x5 matrix of random numbers between 0 and 1.

MATLAB
R = [1](2, 5);
Drag options to blanks, or click blank then click option'
Arand
Beye
Czeros
Dones
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ones' or 'zeros' creates matrices with fixed values, not random.
Using 'eye' creates an identity matrix, which is square and not random.
4fill in blank
hard

Fill both blanks to create a 5x5 matrix of ones and then replace the diagonal with zeros.

MATLAB
M = [1](5);
M([2]) = 0;
Drag options to blanks, or click blank then click option'
Aones
Beye
C1:6:numel(M)
Dzeros
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'eye' instead of 'ones' creates an identity matrix, not a matrix of ones.
Using 'zeros' to create the matrix will not fill it with ones first.
5fill in blank
hard

Fill all three blanks to create a 3x4 matrix of random numbers, then create a 4x4 identity matrix, and finally a 2x2 matrix of zeros.

MATLAB
A = [1](3, 4);
B = [2](4);
C = [3](2, 2);
Drag options to blanks, or click blank then click option'
Arand
Beye
Czeros
Dones
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the functions and their sizes.
Using 'ones' instead of 'zeros' for the last matrix.