3D plot matlab from X Y Z data and integrating a slice function

Hi I have a data formated in CSV file (unfortunately I cannot upload it cause it exceeds 5MB even if I compressed the file). However, my data is composed of 3 coordinates system XYZ which is assigned to a certain energy.
e.g.
X Y Z Energy
0 0 1 48
having a dimension of 100 x 100 x 100
I tried this following code
###
Array=csvread('processedata.csv');
X = Array(:, 1);
Y = Array(:, 2);
Z = Array(:, 3);
data = Array(:, 4);
colormap turbo
s=scatter3(X,Y,Z,20,data,'filled','s','MarkerEdgeColor','none') % draw the scatter plot
alpha(s,.1)
ax = gca;
ax.XDir = 'reverse';
%view(-31,14)
% create and label the colorbar
cb = colorbar;
caxis([0 38.1])
xlabel('X')
ylabel('Y')
zlabel('Z')
cb.Label.String = 'Dose';
###
and the output is this
but I wanted to show like this instead with a grid box and slices so that could see what is happeninng inside the box

 Accepted Answer

If you have a regular grid of x y z points, then pull out the columns and reshape() and possibly permute() into an appropriate sized 3D grid of energy.
If the points are not regular, then pull out min and max x y z and linspace() vectors and ndgrid() to construct matrices X Y Z of coordinates to approximate the data at. Then scatteredInterpolant(x, y, z, Energy) and evaluate the resulting function at X Y Z to get a grid of energy.
Either way, you now have a 3D grid of energy that you can use slice() with.

5 Comments

I have attached the file.
I have followed your innstruction but seems the slice needs to have an input of a volume
Array=csvread('processedata.csv');
X = Array(:, 1);
Y = Array(:, 2);
Z = Array(:, 3);
D = Array(:, 4);
A = reshape([X;Y;Z],[],3);
I=scatteredInterpolant(X1,Y1, Z1, D)
slice(X1,Y1,Z1, A, 0, [],[])
You have 50 unique X values, 100 unique Y values, 100 unique Z values. They form a grid of values. However, instead of 500000 points, you have over 900000 points -- so you have about 1.8 values on average for each location. scatteredInterpolant will average the values at any one location.
Array=csvread('processedata.csv');
X = Array(:, 1);
Y = Array(:, 2);
Z = Array(:, 3);
D = Array(:, 4);
ux = unique(X);
uy = unique(Y);
uz = unique(Z);
[XG, YG, ZG] = meshgrid(ux, uy, uz);
F = scatteredInterpolant(X, Y, Z, D);
DG = F(XG, YG, ZG);
slice(XG, YG, ZG, DG, 0, [], [])
You have a lot of points, about half a million. Trying to plot them all would be really slow. The range is about -2800 to +89 . Even just an isosurface at +80 is slow as there are over 10000 irregularly-placed points above +80. It is difficult to see any structure in the data. I recommend that you
histogram(DG(:), 100)
and look at the distribution (and keep in mind that only 1% population would still be ~5000 points)
I am actually trying out different representations of my data and I agree about your point that I can hardly see any structure of my data. However, I have see some pattern from it. A big thanks for your help Walter, you're the best!
I think you might need to project your 4D data (three independent, one dependent) into 3D so that you have a chance of seeing continuous changes in a recognizable way. isosurfaces look just too irregular to make sense out of.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!