Different color for every point - Scatter3

4 views (last 30 days)
Diego Hens
Diego Hens on 19 Nov 2020
Edited: KALYAN ACHARJYA on 19 Nov 2020
Hello,
I'm using the function Scatter3 to plot a variable number of points (I use the function getpts to click on an existing plot and get the points), for example a 2x4 matrix (x and y coordinates). As I said, it's variable depending on how many times I click, so it could also be a 2x1 or 2x5 (etc) matrix. Then I use this points to draw them on another scatter3 figure.
It would be tremendously helpful if I could have every point have a different color, it doesn't matter which. It would help me determine where each point is plotted on the other figure.
Can you help me figure this out?

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 19 Nov 2020
Edited: KALYAN ACHARJYA on 19 Nov 2020
"It would be tremendously helpful if I could have every point have a different color, it doesn't matter which. It would help me determine where each point is plotted on the other figure."
One Way: Sample data example is taken from MATLAB docs
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
figure,scatter3(x,y,z);
% Now plot the same with different colors
figure;
for i=1:length(x)
plot3(x(i),y(i),z(i),'o');
hold on
grid on;
end

Community Treasure Hunt

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

Start Hunting!