Bar graphs - color coding..
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Hello,
I need to color code my bar graph.
a = [10 20 30 25 15] b = [1 3 2 1 4] bar(a)
BUT, I want a(1) and a(4) the same color because b(1) and b(4) = 1; a(2), a(3) and a(5) each a different color because b(2,3 and 5) are different.
Thanks, S
0 Kommentare
Akzeptierte Antwort
  Azzi Abdelmalek
      
      
 am 5 Mär. 2013
        close
a = [10 20 30 25 15] 
b = [1 3 2 1 4] 
cl='rgbmc'
for k=1:numel(a)
  bar(k,b(k),cl(b(k)))
  hold on
end
set(gca,'Xtickmode','auto')
set(gca,'Xtick',1:k)
0 Kommentare
Weitere Antworten (1)
  sas0701
 am 5 Mär. 2013
        2 Kommentare
  Azzi Abdelmalek
      
      
 am 5 Mär. 2013
				
      Bearbeitet: Azzi Abdelmalek
      
      
 am 6 Mär. 2013
  
			close
a = [10 20 30 25 15] 
b = [1 3 2 1 4] 
cl= [0 0 1; 1 0 1;0 1 0;1 0 0; 0 1 1;  1 1 0; 0 0 0;  1 0.5 0];
for k=1:numel(a)
h=bar(k,b(k),'Facecolor',cl(b(k),:))
hold on
end
Siehe auch
Kategorien
				Mehr zu Histograms finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

