Constructing a 3D matrix out of single column coordinate data with a corresponding value

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 Comments

What would the voxels of the 3D matrix contain, and how would those contents be related to the imported data?
Each voxel would contain a velocity value at a certain coordinate.

Sign in to comment.

 Accepted Answer

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 Comments

Hi thanks for your help,
But this Matrix3D returns like 763x763x763, but expect it to be 188^3, since the length of the columns are also 188^3, and the coordinates are retracted from a perfect cube. Besides that, when i select some random parts of this creacted matrix and i analayze them, i find only zeros, which cannot be the case. I will display a part of "xyzv" matrix below.:
-0.000520000001000000 0.00228000013000000 -0.00444000028000000 0.0914448053000000
-0.000520000001000000 0.00228000013000000 -0.00435999967000000 0.0867100433000000
-0.000520000001000000 0.00236000004000000 -0.00444000028000000 0.0901703462000000
-0.000520000001000000 0.00236000004000000 -0.00435999967000000 0.0832454637000000
-0.000600000028000000 0.00228000013000000 -0.00427999999000000 0.0638148636000000
-0.000600000028000000 0.00228000013000000 -0.00420000032000000 0.0449321158000000
-0.000600000028000000 0.00236000004000000 -0.00427999999000000 0.0659241527000000
-0.000600000028000000 0.00236000004000000 -0.00420000032000000 0.0842402205000000
-0.000520000001000000 0.00228000013000000 -0.00427999999000000 0.0794742778000000
-0.000520000001000000 0.00228000013000000 -0.00420000032000000 0.0790982544000000
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
You are a hero! It works, thanks a lot.

Sign in to comment.

More Answers (1)

If you are trying to query velocity values at arbitrary 3D locations, do not use a 3D array. Instead, use scatteredInterpolant or griddata.

3 Comments

I don't want the data to be interpolated before filtering yet. And the output of the scatteredinterpolant does not return a 3d matrix with x times y times z.
But you don't possess velocity values at all points in a 3D lattice, only at some scattered cloud of (x,y,z) coordinates around them. How will you define values at the lattice points if not by interpolation?
But I do have all the points in a 3D lattice I believe.

Sign in to comment.

Categories

Find more on Geoscience in Help Center and File Exchange

Products

Release

R2023b

Tags

Asked:

on 28 Mar 2024

Edited:

on 29 Mar 2024

Community Treasure Hunt

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

Start Hunting!