Constructing a 3D matrix out of single column coordinate data with a corresponding value
26 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I need to analyze a 3d velocity field from tecplot. I could transfer the data into a 4 column matrix consisting of 6644672 rows. The first three columns represent that XYZ respectively, and the fourth column is the velocity data at that coordinate.
Since I want to filter this field in the future, I for now need to construct a 3d Matrix out of this imported data. It is important that no coordinates get lost, that the velocity value stays at the right coordinate and that the coordinates are oriented in the right way to eachother.
The challenging thing for me was that the coordinates in the 4 column matrix are not ordered in some logical way.
Can someone help me?
2 件のコメント
Catalytic
2024 年 3 月 28 日 20:57
What would the voxels of the 3D matrix contain, and how would those contents be related to the imported data?
採用された回答
Matt J
2024 年 3 月 28 日 21:29
編集済み: Matt J
2024 年 3 月 28 日 21:29
Let's call your Nx4 matrix XYZV.
xyzv=num2cell(sortrows(XYZV,[3,2,1]) ,1);
[I,J,K,V] =deal(xyzv{:});
I=findgroups(I);
J=findgroups(J);
K=findgroups(K);
matrix3D=accumarray([I,J,K], V); %the result
3 件のコメント
Matt J
2024 年 3 月 29 日 13:25
It means your (x,y,z) data do not sweep over a cube exactly. You could try the modification below, which allows the (x,y,z) to deviate from the nodes of a cube with a tolerance, but I don't/can't know what the appropriate TOL for your data would be.
TOL=1e-4; %example
I=findgroupstol(I,TOL);
J=findgroupstol(J,TOL);
K=findgroupstol(K,TOL);
function G=findgroupstol(U,tol)
[~,~,G]=uniquetol(U,tol);
end
その他の回答 (1 件)
Matt J
2024 年 3 月 28 日 20:53
編集済み: Matt J
2024 年 3 月 28 日 21:05
If you are trying to query velocity values at arbitrary 3D locations, do not use a 3D array. Instead, use scatteredInterpolant or griddata.
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!