Can I define or change the direction of 'reshape'?

25 ビュー (過去 30 日間)
Salad Box
Salad Box 2023 年 1 月 31 日
コメント済み: Salad Box 2023 年 2 月 1 日
Hi,
I have a sample image (below).
Generally if I use 'reshape' to change the RGB from n by m by 3 to n*m by 3, the reshape process goes vertically (in the direction of A), meaning the pixel at 1st row and 1st column is followed by the pixel at 2nd row and 1st column.
How can I define 'reshape' (or whether it is possible) so that the reshape goes horizontally (in the direction of B), meaning the pixel at 1st row and 1st column is followed by the pixel at 1st row and 2nd column?

採用された回答

John D'Errico
John D'Errico 2023 年 1 月 31 日
編集済み: John D'Errico 2023 年 1 月 31 日
No. You cannot do so. You cannnot change how reshape works.
HOWEVER. Nothing stops you from changing that afterwards. For example...
V = 1:16;
Vr = reshape(V,[4 4])
Vr = 4×4
1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
So down the columns. That is how reshape works. And you cannot change it.
Vr = Vr'
Vr = 4×4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
But now acrross the rows.
You can also use permute for arrays in higher dimensions.
  1 件のコメント
Salad Box
Salad Box 2023 年 2 月 1 日
That really helps. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by