Generating scalar volume data, now in x,y,z,v columns

26 views (last 30 days)
This seems to be a common problem to which I found no direct answer.
I'm trying to visualize a data set of energy values depending on xyz-location, therefore a 4-D plot of scalar volume data. My data is now in form of a speardsheet with columns for x, y, z coordinates (each -0,5 - 0,4 on 0,1 intervals) and one for energy. In short, one row contains information on the location and corresponding energy. I have separated them in different variables (four 1000x1 arrays; X, Y, Z and E).
My goal would be to produce something like this. This far I have gathered that I should use isosurfaces with transparency and I think I'll manage that thanks to tutorial videos. However I have not found a way to produce necessary arrays for the job. I used
[x,y,z] = meshgrid(-0.5:0.1:0.4,-0.5:0.1:0.4,-0.5:0.1:0.4)
to genarate arrays for the coordinates, but I haven't found a way of making a corresponding array of my energies.
Ideal solution would of course read my datafile and produce correct energy array on its own, preferably even the x,y,z arrays. Since that may be hard to do(?), I would also be happy to be able to load data systematicly from one variable (1000x1) into "blank" 10x10x10 array, since I can sort my data beforehand in proper order when I know in which order the array is filled.
I'm fairly new to Matlab, so I would appreciate clear instructions, links to tutorials or documentation I didn't found on my own.

Accepted Answer

Patrick Kalita
Patrick Kalita on 14 Feb 2011
You will want to use the TriScatteredInterp class to interpolate the scattered data to a grid of points that is needed for isosurface. Here is an example:
% The point cloud data:
x = 2*rand(500,1) - 1;
y = 2*rand(500,1) - 1;
z = 2*rand(500,1) - 1;
e = x.^2 + y.^2 + z.^2;
% Generate the grid of points where the interpolated values will be calculated
[xg,yg,zg] = meshgrid(-1 : 0.05 : 1);
% Create the interpolating object
F = TriScatteredInterp(x, y, z, e);
% Do the interpolation
eg = F(xg,yg,zg);
% Now you can use isosurface with the gridded data
isosurface(xg,yg,zg,eg,0.75);
  2 Comments
Lasse Karhu
Lasse Karhu on 14 Feb 2011
I actually came across TriScatterInterp on my own. With our help I was even able to visualize the produced data. :)
Am I correct in pressuming that the second step is done because of the interpolation and by adjusting the step I can smoothen the image?
Patrick Kalita
Patrick Kalita on 14 Feb 2011
Yes, adjusting the step size could help produce a smoother result. Having enough input (scattered) data points also helps. You can also set the 'method' property of the TriScatteredInterp object to 'natural' to get a smoother result, as well, at the expense of longer computation time.

Sign in to comment.

More Answers (2)

Matt Fig
Matt Fig on 14 Feb 2011
Try using NDGRID instead of MESHGRID. Read carefully the help for NDGRID, because the output order differs from that of MESHGRID.
  1 Comment
Andrew Newell
Andrew Newell on 14 Feb 2011
I don't think this will work because E is probably not a regularly repeating value.

Sign in to comment.


Andrew Newell
Andrew Newell on 14 Feb 2011
Assuming you have read in X,Y,Z,E, and no grid points are missing, you can sort the points in a way that simulates MESHGRID as follows:
mat = [X(:) Y(:) Z(:) E(:)];
mat = sortrows(mat,[3 1 2]);
X = reshape(mat(:,1),[10 10 10]);
Y = reshape(mat(:,2),[10 10 10]);
Z = reshape(mat(:,3),[10 10 10]);
E = reshape(mat(:,4),[10 10 10]);
Now plot using
isovalue = 0.5; % or whatever
isosurface(X,Y,Z,E,isovalue)
  2 Comments
Lasse Karhu
Lasse Karhu on 14 Feb 2011
The dataset is perfect, although future ones may not be. It works fine and will sure come in handy if actual interpolation is not needed!
I'm making sure that I understood correctly; this is only brutally reformating my data into correct format? If so, this was exactly what I was looking for.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!