Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot 3D points in Matlab

Tags:

plot

matlab

3d

I want to plot 3D points in Matlab in different colors depending on a value. I've got following code, but this does not work because plot3d needs a vector.

x = vdhf_data.data(:,1);
y = vdhf_data.data(:,2);
z = vdhf_data.data(:,3);
data = vdhf_data.data(:,4);

grid on
hold all

for k=1:length(x)
    if data(k) < 6  
        plot3d(x(k), y(k), z(k), 'ws--', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r')
    else
        plot3d(x(k), y(k), z(k), 'ws--', 'MarkerEdgeColor', 'g', 'MarkerFaceColor', 'g')
    end
end

How to do that in Matlab?

like image 730
Razer Avatar asked Feb 23 '12 14:02

Razer


1 Answers

I would use

scatter3(x,y,z,ones(size(x)),data,'filled')

This will plot all the points at the same size and color them according to the value of data, using the current colormap. You can also use data to scale the size of each point.

scatter3(x,y,z,data.^-2,data,'filled')
like image 169
zamazalotta Avatar answered Sep 17 '22 23:09

zamazalotta