Opening the book…
MATLAB has several functions for rearranging or extracting parts of a matrix.
|
Function |
Meaning |
| reshape(A, m, n) | changes the dimensions of A without changing the total number of elements |
|
fliplr(A) |
Flips the matrix left to right |
|
flipud(A) |
Flips the matrix upside down |
|
rot90(A) |
Rotates the matrix 90 degrees counterclockwise |
|
tril(A) |
Returns the lower triangular part of A |
|
triu(A) |
Returns the upper triangular part of A |
Rearranging a 2D array.
Solution
arr_1 =
3 2 1
6 5 4
9 8 7
8 12 3
arr_2 =
3 12 8
7 8 9
4 5 6
1 2 3
arr_3 =
3 6 9 8
2 5 8 12
1 4 7 3
arr_4 =
1 0 0
4 5 0
7 8 9
3 12 8
arr_5 =
1 2 3
0 5 6
0 0 9
0 0 0
arr_6 =
1 3 8 6
4 2 12 9
7 5 3 8
When using the reshape function, the new shape must contain the same total number of elements as the original array. Also remember that MATLAB fills the reshaped array column by column. This may not always match what you expect if you are thinking row by row.
This page titled 4.11: More Matrix Functions was last modified on Tue, 30 Jun 2026 02:11:57 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.