Question

I have a large set of data that I've collected that I'd like to display in a 3-D scatter plot. The data is contained in a text file.

The data is organized like so

1 1 1 10.8
2 1 1 3.4
4 1 1 6.1
8 1 1 4.5
1 2 1 7.8
...
8 8 8 11.9

The first three tokens in each line should represent (x,y,z) points. In the 3-D scatter plot, there should be a dot for each of these points.

The color of the dots depends on the fourth token. Basically, the closer the fourth parameter is to the max value, the closer it will be to the color red. The close the fourth parameter is to the min value, the bluer it will be.

I'm pretty sure that the scatter3(X,Y,Z,S,C) function does this, but I'm not an expert.

Here's what my data variable contains:

Data Variable

Was it helpful?

Solution

Try this (assume data is the array you presented in your question):

x = data(:,1);
y = data(:,2);
z = data(:,3);
s = ones(size(data,1), 1) * 20; %sizes of markers
c = data(:,4); %color data

scatter3(x,y,z,s,c);
colorbar;

Or you can simply do it inline:

scatter3(data(:,1),data(:,2),data(:,3),ones(size(data,1), 1)*20,data(:,4));
colorbar
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top