필터 지우기
필터 지우기

Form a 3D matrix for a 2d matrix

조회 수: 4 (최근 30일)
Luis Isaac
Luis Isaac 2019년 11월 13일
댓글: Matt J 2019년 11월 13일
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

답변 (1개)

Matt J
Matt J 2019년 11월 13일
편집: Matt J 2019년 11월 13일
NewM3D = reshape(ExitVector,size(M3D));
  댓글 수: 2
Matt J
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
Matt J 2019년 11월 13일
[m,n,p]=size(M3D);
NewM3D = permute( reshape(ExitVector,[m,p,n]) ,[1,3,2]);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by