0
0
MATLABdata~10 mins

Reshaping arrays 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 reshape the vector into a 2x3 matrix.

MATLAB
A = 1:6;
B = reshape(A, [1]);
Drag options to blanks, or click blank then click option'
A[2, 3]
B[3, 2]
C[6, 1]
D[1, 6]
Attempts:
3 left
💡 Hint
Common Mistakes
Using dimensions that do not multiply to the total number of elements.
Swapping rows and columns.
2fill in blank
medium

Complete the code to reshape matrix M into a column vector.

MATLAB
M = [1 2 3; 4 5 6];
V = reshape(M, [1]);
Drag options to blanks, or click blank then click option'
A[6, 1]
B[3, 2]
C[1, 6]
D[2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using [1, 6] which creates a row vector instead.
Confusing rows and columns.
3fill in blank
hard

Fix the error in reshaping matrix X into a 3x3 matrix.

MATLAB
X = 1:8;
Y = reshape(X, [1]);
Drag options to blanks, or click blank then click option'
A[3, 3]
B[2, 4]
C[1, 8]
D[4, 2]
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to reshape into a size that does not match the number of elements.
Ignoring the error message from MATLAB.
4fill in blank
hard

Fill both blanks to reshape vector V into a 4x2 matrix and then back to a 2x4 matrix.

MATLAB
V = 1:8;
M1 = reshape(V, [1]);
M2 = reshape(M1, [2]);
Drag options to blanks, or click blank then click option'
A[4, 2]
B[2, 4]
C[8, 1]
D[1, 8]
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of rows and columns.
Using incompatible dimensions that don't match the number of elements.
5fill in blank
hard

Fill all three blanks to create a 3D array from vector W and then reshape it back to a 2D matrix.

MATLAB
W = 1:12;
A = reshape(W, [1], [2], [3]);
B = reshape(A, [4, 3]);
Drag options to blanks, or click blank then click option'
A2
B3
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing dimensions that do not multiply to 12.
Confusing the order of dimensions.