Challenge - 5 Problems
Array Reshaper Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Remember MATLAB fills matrices column-wise when reshaping.
✗ Incorrect
The reshape function fills the new matrix column-wise from the original vector. So the first column is [1;2], second is [3;4], third is [5;6].
❓ Predict Output
intermediate2:00remaining
Reshape with incompatible size
What error does this MATLAB code produce?
MATLAB
A = 1:10; B = reshape(A, 3, 4);
Attempts:
2 left
💡 Hint
Check if the total number of elements matches the new shape.
✗ Incorrect
reshape requires the total number of elements to remain the same. 10 elements cannot fill a 3x4 (12 elements) matrix.
🧠 Conceptual
advanced2:00remaining
Understanding reshape order
Given a 2x3 matrix M = [1 2 3; 4 5 6], what is the result of reshape(M, 3, 2)?
Attempts:
2 left
💡 Hint
reshape reads elements column-wise from the original matrix.
✗ Incorrect
The elements are taken column-wise: [1;4;2;5;3;6] and reshaped into 3 rows and 2 columns.
🔧 Debug
advanced2: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);
Attempts:
2 left
💡 Hint
Check if the product of dimensions matches the number of elements.
✗ Incorrect
reshape requires the total elements to match. 12 elements cannot fill 20 slots (4x5). Changing to 3x4 matches 12 elements.
🚀 Application
expert2: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);
Attempts:
2 left
💡 Hint
First reshape fills column-wise, then transpose swaps rows and columns.
✗ Incorrect
reshape(A,2,3) creates a 2x3 matrix filled column-wise: [1 3 5; 2 4 6]. Transpose swaps rows and columns to get [1 2; 3 4; 5 6].