How to reshape a 2D to 3D matrix without using loops (reshape) and keeping a particular order of the elements// Wrong arragement of elemts after using "reshape"
조회 수: 1 (최근 30일)
이전 댓글 표시
I've a problem using the reshape function. I've a Matrix A: A =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
I want to change it to a 3D Matrix with the size 4x4x3. When I use reshape like this:
A2=repmat(A,4,4,3); the result is:
A2(:,:,1) =
1 1 1 2
5 5 5 6
9 9 9 10
13 13 13 14
A2(:,:,2) =
2 2 3 3
6 6 7 7
10 10 11 11
14 14 15 15
A2(:,:,3) =
3 4 4 4
7 8 8 8
11 12 12 12
15 16 16 16
The result I want though is:
A2(:,:,1) =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
A2(:,:,2) =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
A2(:,:,3) =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
In the real data set I've different values, I just chose (1:16) 3 Times to show in what order I want to rearrange the data/Matrix.
Thanks a lot!
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2014년 3월 30일
편집: Azzi Abdelmalek
2014년 3월 30일
A=[1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16]
A2=permute(reshape(A',4,4,[]),[2 1 3])
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!