trivial matrix question: how to rearrange matrices in a given order

1 回表示 (過去 30 日間)
Enzo
Enzo 2023 年 4 月 27 日
コメント済み: Matt J 2023 年 4 月 28 日
Hello everyone,
I know this could seems trivial and meybe here we are talking about the very matlab basics, but as I am dealing with really big data structures, I would like to receive some support.
I have the following matrix, as shown in 1:
I would like to reshape it to be as in 2, and back again to point 1.
Thanks in advance

採用された回答

Matt J
Matt J 2023 年 4 月 27 日
編集済み: Matt J 2023 年 4 月 27 日
You can use blkColon in this FEX download,
>> X
X(:,:,1) =
1 10 19
2 11 20
3 12 21
X(:,:,2) =
4 13 22
5 14 23
6 15 24
X(:,:,3) =
7 16 25
8 17 26
9 18 27
>> Y=blkColon(X,[3,3])
Y =
1 10 19
2 11 20
3 12 21
4 13 22
5 14 23
6 15 24
7 16 25
8 17 26
9 18 27
  2 件のコメント
Enzo
Enzo 2023 年 4 月 28 日
@Matt J thanks for your precious help. I am gonna accept your answer has it worked perfectly. Do you have any suggestion on how to reshape the Y matrix again into the X matrix shape?
Matt J
Matt J 2023 年 4 月 28 日
Yes, you can use blkReshape().

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

その他の回答 (1 件)

chicken vector
chicken vector 2023 年 4 月 27 日
編集済み: chicken vector 2023 年 4 月 27 日
A = reshape(1:3^3,3^2,[])
A = 9×3
1 10 19 2 11 20 3 12 21 4 13 22 5 14 23 6 15 24 7 16 25 8 17 26 9 18 27
B = permute(reshape(A',[],3,3),[2,1,3])
B =
B(:,:,1) = 1 10 19 2 11 20 3 12 21 B(:,:,2) = 4 13 22 5 14 23 6 15 24 B(:,:,3) = 7 16 25 8 17 26 9 18 27
A = reshape(B,[],3)
A = 9×3
1 4 7 2 5 8 3 6 9 10 13 16 11 14 17 12 15 18 19 22 25 20 23 26 21 24 27

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by