How to convert 1D matrix to 3D matrix with specific order.

11 ビュー (過去 30 日間)
Eric Jiang
Eric Jiang 2016 年 7 月 21 日
コメント済み: Eric Jiang 2016 年 7 月 22 日
I have a 1D matrix (1 by 6,000,000) of data. I want to reshape this to a three dimensional matrix that is 100 by 100 by 600. However, when I use the reshape function, the order of the numbers comes out incorrect.
For example: (12 numbers)
a=
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
0.11
0.12
I want b to be: (assume 2 by 2 by 3)
b(:,:,1)=
0.01 0.07
0.04 0.10
b(:,:,2)=
0.02 0.08
0.05 0.11
b(:,:,3)=
0.03 0.09
0.06 0.12
Basically, the order that I want is if the x axis had 2 points, y axis had 3 points, and z axis had 2 points, Point 1 would be (x1, y1, z1), Point 2 would be (x1, y1, z2), Point 3 would be (x2, y1, z1), Point 4 would be (x2,y1,z2), Point 5 would be (x1, y2, z1), Point 6 would be (x1, y2,z2), Point 7 would be (x2,y2,z1), Point 8 would be (x2,y2,z2) and on to Point 12.
What is the most efficient way to do this?
Thank you.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 22 日
編集済み: Azzi Abdelmalek 2016 年 7 月 22 日
a=0.01:0.01:0.60
%you want a nxmxp matrix with:
n=3
m=4
p=5
out=permute(reshape(a,p,n,m),[2,3,1])
You can apply this to your case 2x2x3 matrice
a=0.01:0.01:0.12
n=2
m=2
p=3
out=permute(reshape(a,p,n,m),[2,3,1])
  1 件のコメント
Eric Jiang
Eric Jiang 2016 年 7 月 22 日
Thank you very much!
This was exactly what I was looking for.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by