how to color my scatter3 values according to a cluster label

hi guys, so i am stuck on coloring my xyz values separately while using the scatter3 func.
so i have this code
load('../mat/coor.mat') % where the coor nodes are stored
x = coor(:,1); % correspond xyz to values on coor
y = coor(:,2);
z = coor(:,3);
scatter3(x,y,z,100);
where i correspond my xyz values to the values on my coor file and then i make a scatter3 plot of those values.
My next step is to color these xyz values according to my specific cluster labels that are stored in a separate matrix titled 'ciu' which is a 384x1 matrix with k=1,2, and 3. How would I go about doing that?
Any help would be appreciated, thank you so much!
Edit: more background
So coor.mat is a 384x3 matrix, meaning that coor.mat line 1 directly corresponds to ciu-matrix line 1. For example, (x1,y1,z1) = 1, (x2,y2,z2) = 3, etc.
What I want to do is to write a line that has matlab make that connection and then assign each of the three cluster labels their own color on the plot generated via scatter3.

 Accepted Answer

6 Comments

hi, for the project im doing, i can't really use gscatter, i've been instructed to stick to scatter3.
Are the elements of ciu integers corresponding to the cluster number?
yess, they do. sorry i just rememered that, i'll add it in to the original post. But yes, line 1 on coor.mat corresponds with line 1 on ciu. So ex. (x1,y1,z1) = 1, (x2,y2,z2) = 3, etc.
In that case, you can try something like this
load('../mat/coor.mat') % where the coor nodes are stored
x = coor(:,1); % correspond xyz to values on coor
y = coor(:,2);
z = coor(:,3);
colors = rand(length(unique(ciu)), 3); % generate random rgb triples
% according to the number of clusters
Colormap = colors(ciu, :);
scatter3(x,y,z,100,Colormap);
yayy that works! Thank you so much!

Sign in to comment.

More Answers (0)

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!