Recall & Review
beginner
What does the
reshape function do in MATLAB?The
reshape function changes the size and shape of an array without changing its data. It rearranges elements into a new dimension.Click to reveal answer
beginner
How do you reshape a 1x6 array into a 2x3 array in MATLAB?
Use
reshape(array, 2, 3). This changes the array to have 2 rows and 3 columns.Click to reveal answer
beginner
What must be true about the number of elements when reshaping an array?
The total number of elements must stay the same before and after reshaping. For example, a 6-element array can be reshaped to 2x3 or 3x2, but not 4x2.
Click to reveal answer
intermediate
What happens if you try to reshape an array to a size that doesn't match the number of elements?
MATLAB gives an error because the reshape function requires the total number of elements to remain constant.
Click to reveal answer
intermediate
How does MATLAB fill the reshaped array?
MATLAB fills the reshaped array column-wise, taking elements from the original array in column-major order.
Click to reveal answer
What does
reshape(A, 3, 2) do if A is a 1x6 array?✗ Incorrect
The reshape function changes the shape to 3 rows and 2 columns, keeping all elements.
What must be true for reshape to work without error?
✗ Incorrect
The total number of elements must remain the same to reshape successfully.
If you have a 2x3 matrix, which reshape is valid?
✗ Incorrect
2x3 has 6 elements, so reshaping to 3x2 (also 6 elements) is valid.
How does MATLAB fill elements when reshaping?
✗ Incorrect
MATLAB fills reshaped arrays column-wise, following its column-major order.
What happens if you try
reshape(A, 4, 2) on a 2x3 matrix?✗ Incorrect
Because 2x3 has 6 elements and 4x2 requires 8, MATLAB throws an error.
Explain how the
reshape function works in MATLAB and what rules must be followed.Think about how you can rearrange a box of items without adding or losing any.
You got /4 concepts.
Describe a real-life example that helps you understand reshaping arrays.
Imagine moving books from one shelf layout to another.
You got /4 concepts.