0
0
MATLABdata~20 mins

Matrix creation in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this matrix creation code?
Consider the following MATLAB code that creates a matrix. What will be the resulting matrix?
MATLAB
A = zeros(2,3) + eye(2,3); disp(A);
A[0 0 0; 0 0 0]
B[1 0; 0 1; 0 0]
C[1 0 0; 0 1 0]
D[1 1 1; 1 1 1]
Attempts:
2 left
💡 Hint
Remember that eye(m,n) creates an m-by-n matrix with ones on the main diagonal and zeros elsewhere.
Predict Output
intermediate
1:30remaining
What is the size of the matrix created?
What is the size of the matrix B created by this MATLAB code?
MATLAB
B = ones(4) * 5;
A4x4
B5x5
C4x1
D1x4
Attempts:
2 left
💡 Hint
ones(n) creates an n-by-n matrix of ones.
Predict Output
advanced
2:00remaining
What does this matrix creation code output?
What is the output of this MATLAB code snippet?
MATLAB
C = diag([3 4 5]); disp(C);
A[3 0 0; 4 0 0; 5 0 0]
B[3 4 5; 0 0 0; 0 0 0]
C[0 3 0; 0 4 0; 0 0 5]
D[3 0 0; 0 4 0; 0 0 5]
Attempts:
2 left
💡 Hint
The diag function creates a diagonal matrix from the input vector.
Predict Output
advanced
2:30remaining
What is the output of this matrix concatenation?
What matrix does this MATLAB code produce?
MATLAB
D = [1 2; 3 4]; E = [5 6; 7 8]; F = [D E; E D]; disp(F);
A[1 2 5 6; 3 4 7 8; 5 6 1 2; 7 8 3 4]
B[1 2 3 4; 5 6 7 8; 1 2 3 4; 5 6 7 8]
C[1 2 5 6; 3 4 7 8; 1 2 5 6; 3 4 7 8]
D[5 6 1 2; 7 8 3 4; 1 2 5 6; 3 4 7 8]
Attempts:
2 left
💡 Hint
Square brackets concatenate matrices horizontally and vertically.
Predict Output
expert
3:00remaining
What is the output of this complex matrix creation code?
What is the output of this MATLAB code snippet?
MATLAB
G = repmat([1 2; 3 4], 2, 3); disp(G);
A[1 2 1 2; 3 4 3 4; 1 2 1 2; 3 4 3 4]
B[1 2 1 2 1 2; 3 4 3 4 3 4; 1 2 1 2 1 2; 3 4 3 4 3 4]
C[1 2 3 4 1 2; 3 4 1 2 3 4; 1 2 3 4 1 2; 3 4 1 2 3 4]
D[1 2 3 4 5 6; 7 8 9 10 11 12; 1 2 3 4 5 6; 7 8 9 10 11 12]
Attempts:
2 left
💡 Hint
repmat repeats the matrix the specified number of times in rows and columns.