0
0
MATLABdata~20 mins

Reshaping arrays in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Reshaper Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of reshaping a matrix
What is the output of the following MATLAB code?
MATLAB
A = [1 2 3 4 5 6];
B = reshape(A, 2, 3);
disp(B);
A[1 3 5; 2 4 6]
B[1 2; 3 4; 5 6]
C[1 4; 2 5; 3 6]
D[1 2 3; 4 5 6]
Attempts:
2 left
💡 Hint
Remember MATLAB fills matrices column-wise when reshaping.
Predict Output
intermediate
2:00remaining
Reshape with incompatible size
What error does this MATLAB code produce?
MATLAB
A = 1:10;
B = reshape(A, 3, 4);
AError: Dimensions do not agree.
BError: Number of elements must not change.
CError: reshape cannot reshape array of length 10 into 3-by-4 matrix.
DNo error, outputs a 3x4 matrix with zeros padded.
Attempts:
2 left
💡 Hint
Check if the total number of elements matches the new shape.
🧠 Conceptual
advanced
2:00remaining
Understanding reshape order
Given a 2x3 matrix M = [1 2 3; 4 5 6], what is the result of reshape(M, 3, 2)?
A[1 5; 2 6; 3 4]
B[1 2 3; 4 5 6]
C[1 3 5; 2 4 6]
D[1 5; 4 3; 2 6]
Attempts:
2 left
💡 Hint
reshape reads elements column-wise from the original matrix.
🔧 Debug
advanced
2:00remaining
Fix the reshape dimension mismatch
Why does this code produce an error and how to fix it? A = 1:12; B = reshape(A, 4, 5);
MATLAB
A = 1:12;
B = reshape(A, 4, 5);
AError because 12 elements cannot fill a 4x5 matrix; fix by changing to reshape(A, 3, 4).
BError because reshape requires square matrices; fix by using reshape(A, 4, 4).
CNo error; outputs a 4x5 matrix with last 8 elements zero-padded.
DError because A is a row vector; fix by transposing A before reshape.
Attempts:
2 left
💡 Hint
Check if the product of dimensions matches the number of elements.
🚀 Application
expert
2:00remaining
Reshape and transpose combined
What is the output of this MATLAB code?
MATLAB
A = [1 2 3 4 5 6];
B = reshape(A, 2, 3)';
disp(B);
A[1 3 5; 2 4 6]
B[1 2; 3 4; 5 6]
C[1 4; 2 5; 3 6]
D[1 2 3; 4 5 6]
Attempts:
2 left
💡 Hint
First reshape fills column-wise, then transpose swaps rows and columns.