Form a 3D matrix for a 2d matrix

3 ビュー (過去 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 Center および File ExchangeComputational Geometry についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by