Form a 3D matrix for a 2d matrix
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear
I have a 3d matrix M3D in which each dimension represent one of the spatial coordinates x, y, z. This spatial coordinates are in three vectors xVector, yVector and zVector.
I need to perform a calculation using a function which need these coordinates SomeFun(x,y,z). The function is vectored so for a matrix with n points and 3 columns, each row represent three coordinates, gives a vector of results.
To form this such of matrix from spatial vectors I use the matlab function “combvec”:
EntranceMatrix=combvec(xVector, yVector, zVector)';
ExitVector=SomeFun(EntranceMatrix);
The result is an ExitVector so the ExitVector(i) is the result of EntranceMatrix(i,:)
I would like to put ExitVector in the same form of the original 3d Matrix, i.e. form EntranceVector and ExitVector form a NewM3D, so every element NewM3D(i,j,k) has the same spacial correspondence to M3D(i,j,k).
How can I do it?
Thanks in advance
댓글 수: 0
답변 (1개)
Matt J
2019년 11월 13일
편집: Matt J
2019년 11월 13일
NewM3D = reshape(ExitVector,size(M3D));
댓글 수: 2
Matt J
2019년 11월 13일
Luis' comment moved here:
Thanks very much
But there is a problem in my quetion, I forget to say that xVector represent the first dimension in M3D, yVector is the third dimension (not the second) and zVector is the second dimension.
So If M3D is a matrix 40 x 57 x 60 then xVetor is a vectror of 40 elements, yVector has 60 and zVector has 57.
I think that reshape gives the correct answared if yVector was related to the second dimension of M3D
Matt J
2019년 11월 13일
[m,n,p]=size(M3D);
NewM3D = permute( reshape(ExitVector,[m,p,n]) ,[1,3,2]);
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!