Plot separate data points in different colors

4 views (last 30 days)
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!

Answers (1)

Sean de Wolski
Sean de Wolski on 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

Tags

Community Treasure Hunt

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

Start Hunting!