How can I convert back correctly a 2D matrix to 3D one?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
I converted my 3D matrix A(464 x 201 x 10957) to 2D matrix in matlab by:
B = reshape(A,size(A,3),[],1);
After I convert B(10957,93264) back to 3D matrix as the original (464 x 201 x10957) by:
C=reshape(B,size(B,2),[],1);
D=reshape(C,464,201,[]);
the produced matrix will not to be same as the original one. How can I convert back the 2D matrix correctly?
Thank you for your help in advance! Beata
댓글 수: 0
답변 (1개)
David Young
2015년 8월 14일
편집: David Young
2015년 8월 14일
First, the resulting array will be the same as the original. Here's a demonstration (making the arrays rather smaller to avoid clobbering memory):
A = rand(464, 201, 57); % demo data
B = reshape(A,size(A,3),[],1);
C=reshape(B,size(B,2),[],1);
D=reshape(C,464,201,[]);
isequal(A, D) % prints 1
Second, you don't need to go via C. Thus
D = reshape(B,464,201,[]);
also makes D the same as A.
But third, what you're doing doesn't look sensible. I can't think why you'd want to give B's first dimension the same size as A's third dimension. Remember that reshape does not change the order of the elements in the underlying vector - it just divides it up differently amongst the dimensions. So B and C are likely to be jumbled up, unless somehow the original structure of A is very special. I wonder if what you really want is permute.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!