Plot data sets with unique colors without using loop
Afficher commentaires plus anciens
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?
Réponses (1)
Image Analyst
le 4 Déc 2017
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
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!