4

With reference to this previous post Getting different colors for different numbers using `spy` in Matlab

where it was suggested the following in order to have different values of spy represented with different colors

spy(a,'k')
hold on
spy(a==10,'r')
spy(a==9,'b')
hold off

How can I do if I would like to use RGB definitions? For example having [ 0.6 0.2 0] for all elements =10 and [0.8 1 0] for all elements =9 instead of the already defined r, b and k etc?

The following does not work because all the Spy matrix will be of a certain color,

set(get(gca,'children'),'color',[0.6 0.2 0])

Thanks, M.

Community
  • 1
  • 1
Matilde
  • 353
  • 5
  • 14

1 Answers1

2

You are very close to the solution. children returns you three results for each of the three inputs, you must index it.

x=get(gca,'children')
set(x(1),'color',firstcolor)
set(x(2),'color',secondcolor)
set(x(3),'color',thirdcolor)
Daniel
  • 36,610
  • 3
  • 36
  • 69