Slice plot of a 3D-data set with color code
Show older comments
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?
Answers (2)
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.
4 Comments
Adam
on 21 Nov 2014
To reply to your answer below which should be a comment on this answer rather than its own answer ideally...
In my example above you should replace those hard-coded numbers with your x, y and z vectors. Often naming convention seems to just be to use capitals for the meshgrid equivalents so e.g.
[X, Y, Z] = meshgrid( x, y, z );
I'm not sure what the simplest way is to get your V vector into the same form, but each element in the 3d arrays X, Y, and Z will correspond to exactly one triple (x,y,z) in your original vectors.
Do you have a V value for every single (x,y,z) triplet? If so you should just be able to do a reshape or reshape and permute to get V matching up with X, Y, Z
Arne
on 21 Nov 2014
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)
Arne
on 24 Nov 2014
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
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!