Plot data sets with unique colors without using loop

My existing code which produces the desired results is as follows,
for i = 1:k
cluster = data(V==i,:);
plot(cluster(:,1),cluster(:,2),'x');
end
'data' is a 1000x2 double array containing x and y coordinates. V is a 1000x1 integer array with values between 1 to k i.e. there are k subsets of data in total
I need to plot the different subsets in different colors which matlab automatically assigns because of individual calls to plot.
Is there a better way to code this without using a loop?

Answers (1)

That uses a color order, which is predefined and which will repeat. To get unique colors you'd have to pass in the color:
for i = 1:k
thisColor = rand(1, 3);
cluster = data(V==i,:);
plot(cluster(:,1), cluster(:,2), 'x', 'Color', thisColor, 'MarkerSize', 15);
end

Asked:

on 4 Dec 2017

Answered:

on 4 Dec 2017

Community Treasure Hunt

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

Start Hunting!