Display matrix values with color coding

8 views (last 30 days)
Hi,
I'm trying to make a figure like this:
It displays a matrix with a color coding: in this example, green for the lowest entries, going towards red for the higher entries.
I made this example in Word - how do I make this in Matlab?

Accepted Answer

Paulo Silva
Paulo Silva on 13 Jul 2011
m=zeros(8,8)+5;
%orange
m(2,5)=8.0;m(1,6)=8.4;m(1,7)=8.6;m(1,8)=8.7;m(2,7)=8.6;m(2,8)=8.3;
%dark green
m(1,4)=7.7;m(1,5)=7.9;m(2,4)=7.1;m(2,6)=7.9;m(3,6)=7.3;m(3,7)=7.4;m(3,8)=7.7;
m(4,7)=7.4;m(4,8)=7.0;m(5,8)=7.0;
%green
m(1,2)=6.6;m(1,3)=6.8;m(2,3)=6.7;m(3,4)=6.7;m(3,5)=6.8;m(4,5)=6.6;m(4,6)=6.7;
m(5,6)=6.5;m(5,7)=6.5;m(6,7)=6.5;m(6,8)=6.7;m(7,8)=6.5;
imagesc(fix(m))
colormap([1 1 1;0 1 0;0.1 0.4 0.1;1 0.5 0]);
set(gca,'XAxisLocation','top')
set(gca,'ydir','reverse')
for n=1:9
line([n-0.5 n-0.5],[0.5 8.5])
line([0.5 8.5],[n-0.5 n-0.5])
end
for n=1:numel(m)
[x,y]=ind2sub(size(m),n);
if m(n)~=5
text(y,x,num2str(m(n)))
end
end
  1 Comment
Frank Meulenaar
Frank Meulenaar on 13 Jul 2011
Awesome (you even added all the word-specific layouts which were not really needed :)), thanks a lot!

Sign in to comment.

More Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 13 Jul 2011

Tags

Community Treasure Hunt

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

Start Hunting!