28 views (last 30 days)

Hello,

I have a rather simple question - tried to reread other posts but it simply doesnt work out so far..

I have several thousands of points in a 3D field - each represented by X,Y and Z value. Each point is described by a fourth number. Coloring should be according to the value of the fourth variable.

I have done a 3D-scatter plot but chances are I miss out interesting things in the middle that are blocked out of my view.

Hence, I would have to do a compilation of slices to visualize the inside. Slice planes should go from the bottom of the 3D-figure to the top.

I know of the slice-function in matlab. But my input arguments produce errors I cannot interprete.

Can someone provide a sample code? Sadly, I could not find one before.

I know that it should be something like -> slice (X,Y,Z,V, PlanevectorX, PlanevectorY, PlanevectorZ)

what would be V in my case?

Adam
on 20 Nov 2014

Edited: Adam
on 21 Nov 2014

I'm not familiar with the slice function, although it does look very useful for the work I do also, but I'm pretty sure that V should be your colour data, of the same size as the X, Y and Z data which should be provided using meshgrid e.g.

[X,Y,Z] = meshgrid(-2:.2:2,-2:.25:2,-2:0.1:2);

The parameterisation of meshgrid should match your sampling to give you X, Y, and Z matrices whose dimensions match your colour values.

Adam
on 21 Nov 2014

The x, y, z in my comment above are now the same as your x, y, z. I changed naming convention from my original answer just to match the way the help names things.

X, Y and Z in my comment answer are the meshgrid outputs that I named x, y, z originally.

(I have now edited my original answer to use consistent variable naming)

Sign in to comment.

matt dash
on 21 Nov 2014

Answer to your updated comment: Use the second output (ind) of histc, which is the index of which bin the rows are in. Then use this to plot subsets of the data.

Example: see how data is binned according to the 4th column (which corresponds to color in the scatter plot)

data = rand(10000,4)

[counts,ind]=histc(data(:,4),[0 0.25 0.5 0.75 1]);

for i = 1:max(ind)

figure;

axes;

idx = ind==i;

scatter3(data(idx,1),data(idx,2),data(idx,3),16,data(idx,4),'filled')

set(gca,'clim',[0 1])

end

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/163352-slice-plot-of-a-3d-data-set-with-color-code#comment_250759

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/163352-slice-plot-of-a-3d-data-set-with-color-code#comment_250759

Sign in to comment.