如何用特定颜色绘制矩阵在matlab中的值 [英] How to plot with specific colors the values of a matrix in matlab

查看:534
本文介绍了如何用特定颜色绘制矩阵在matlab中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在matlab工作,我有一个矩阵,我想通过给一个绿色的颜色到每列/行的最低值和红色是其余或不同级别的red-ish的可视化关于这个值与最低值的距离是多远,最后打印其中的值。例如,假设我有以下矩阵:

  0.0085 0.0244 0.0335 0.0312 0.0392 0.0392 
0.0246 0.0078 0.0234 0.0281 0.0395 0.0395
0.0299 0.0295 0.0108 0.0224 0.0598 0.0598
0.0253 0.0317 0.0236 0.0123 0.0583 0.0583
0.0363 0.0337 0.0500 0.0497 0.0038 0.0583

我想实现的是这样的:





有没有办法实现上述结果?



我正在检查pcolor或imagesc函数, t与某事一起。我在



,您可以更改标头返回 minima 颜色,以符合您喜欢的风格。


I am working in matlab and I have a matrix which I would like to visualize it by giving a green-ish color to the lowest values per column/row and red-ish to the rest or different levels of red-ish depending on how close or far this values is from the lowest one and lastly print the values within. For example lets say that I have the following matrix:

0.0085 0.0244 0.0335 0.0312 0.0392 0.0392
0.0246 0.0078 0.0234 0.0281 0.0395 0.0395
0.0299 0.0295 0.0108 0.0224 0.0598 0.0598
0.0253 0.0317 0.0236 0.0123 0.0583 0.0583
0.0363 0.0337 0.0500 0.0497 0.0038 0.0583

what I want to achieve is something like this:

is there anyhow a way to achieve the above result?

I was checking on pcolor or imagesc functions but I couldn't get along with something. I found these links here and here that they kind of try to do something similar but I couldn't get it to change it to my needs. Therefore, does anybody know if it is possible something like that to be done and how?

Thanks.


Update:

In case that I want to add also some titlebars on the top and on the side, look below:

解决方案

Here is a quick option:

A = [0.0085 0.0244 0.0335 0.0312 0.0392 0.0392
    0.0246 0.0078 0.0234 0.0281 0.0395 0.0395
    0.0299 0.0295 0.0108 0.0224 0.0598 0.0598
    0.0253 0.0317 0.0236 0.0123 0.0583 0.0583
    0.0363 0.0337 0.0500 0.0497 0.0038 0.0583];
back = [1 0 0];
headers = [0.5 0.5 0.5];
minima = [0 1 0];
map = [back ; headers; minima];
colormap(map)
[~,ind] = min(A);
B = zeros(size(A));
for k = 1:size(A,2)
    B(ind(k),k) = 1;
end
B = [ones(1,size(B,2))*0.5;B];
B = [ones(size(B,1),1)*0.5 B];
imagesc(B)
axis off
[y,x]=ndgrid((1:size(A,1)),(1:size(A,2)));
row_titles = num2str((1:size(A,1)).'); % could be any vector...
text(ones(size(A,1),1),2:size(A,1)+1,row_titles,'FontSize',16,'HorizontalAlignment','center',...
    'VerticalAlignment','middle','Color','w')
coloumn_titles = num2str((1:size(A,2)).'); % could be any vector...
text(2:size(A,2)+1,ones(size(A,2),1),coloumn_titles,'FontSize',16,'HorizontalAlignment','center',...
    'VerticalAlignment','middle','Color','w')
text(x(:)+1,y(:)+1,num2str(A(:)),'FontSize',16,'HorizontalAlignment','center',...
    'VerticalAlignment','middle')

which gives:

and you can change the headers, back and minima colors to fit your prefered style.

这篇关于如何用特定颜色绘制矩阵在matlab中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆