In: Computer Science
MATLAB
Create a 2 × 3 matrix variable mat. Pass this matrix variable to each of the following functions and make sure you understand the result: flip, fliplr, flipud, and rot90. In how many different ways can you reshape it?
Note: (in addition to the functions listed, rotate the matrix 180 degrees clockwise)
Creating a random 2x3 matrix.
command: mat = rand(2,3)*10
output:
2.9948 7.6017 5.7173 4.9625 1.2664 1.7056
Now applying different commands as given in the problem.
command: flip(mat) -> flips rows (row 1 in place of row 2 and vice- versa)
output:
4.9625 1.2664 1.7056
2.9948 7.6017 5.7173
command: fliplr(mat) -> flips left most column with the right most column
output:
5.7173 7.6017 2.9948
1.7056 1.2664 4.9625
command: flipud(mat) -> flips up and down, here same as flip(mat)
output:
4.9625 1.2664 1.7056
2.9948 7.6017 5.7173
command: rot90(mat) -> rotated mat by 90 degrees in counterclockwise direction
output:
5.7173 1.7056 7.6017 1.2664 2.9948 4.9625
Rotating matrix by 180 degrees in
clockwise:
commands :
fliplr(flip(mat))
output:
1.7056 1.2664 4.9625
5.7173 7.6017 2.9948