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!