
Display matrix values with color coding
17 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个)
Bjorn Gustavsson
2011-7-13
http://www.mathworks.com/matlabcentral/fileexchange/30151-shaded-correlation-table Might be another option.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!