Display matrix values with color coding

조회 수: 5 (최근 30일)
Frank Meulenaar
Frank Meulenaar 2011년 7월 13일
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?

채택된 답변

Paulo Silva
Paulo Silva 2011년 7월 13일
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
Frank Meulenaar
Frank Meulenaar 2011년 7월 13일
Awesome (you even added all the word-specific layouts which were not really needed :)), thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2011년 7월 13일

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by