How to plot points with corresponding colour
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Given I have an excel data where a1 is the first row of data, a2 is the second row of data and b is the corresponding label. B has either blue or red. When I plot it plots it all as a scatter plot but in blue. I want to make the points red when b says red for that label. How do i do this??
0 commentaires
Réponse acceptée
Dyuman Joshi
le 23 Avr 2024
(Assuming there are only red and blue colors for the plot) Use logical indexing -
%Check which elements of B are red
idx = strcmp(B, 'red');
f = figure;
hold on
%plot data with red color
scatter(a1(idx), a2(idx), [], 'r')
%plot data with blue color
scatter(a2(~idx), a2(~idx), [], 'b')
hold off
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!