Plot separate data points in different colors
Afficher commentaires plus anciens
Hi, I'd like to plot data of one research subject, where each data point has a different grey-scale color depending on other data of the same subject.
So, for example: x=[2 5 8 9 3 4 6 4 8 1]
% grey colors of above data points, respectively: [0.1 0.5 0.4 0.2 0.9 0.6 0.8 0.2 0.3 0.1]
plot(x,'col',<here something to have each data point have a different shade of grey>)
I did this in R before which was quite simple, because in R when you give a bigger matrix of colors as input, R recognizes immediately that each data point should have the respective color; Matlab seems to strongly require a 3 element vector as color input.
Many thanks!
Réponses (1)
Sean de Wolski
le 30 Jan 2012
With a for-loop:
x=[2 5 8 9 3 4 6 4 8 1];
c = [0.1 0.5 0.4 0.2 0.9 0.6 0.8 0.2 0.3 0.1];
threeones = [1 1 1];
for ii = 1:numel(H)
line('xdata',ii,'ydata',x(ii),'marker','*','color',c(ii)*threeones)
end
1 commentaire
Joram
le 30 Jan 2012
Catégories
En savoir plus sur Line Plots 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!