matlab矩阵用颜色显示出来,matlab – 如何可视化显示颜色和值的矩阵?

本文介绍如何在MATLAB中使用IMAGESC和TEXT函数将矩阵以颜色形式展示,并通过调整颜色地图、添加数值标签以及处理重叠的轴刻度标签,实现清晰的矩阵可视化。
摘要由CSDN通过智能技术生成

您可以使用内置函数

IMAGESC和

TEXT很容易地创建此类绘图,并调整图形对象的多个参数。这里有一个例子:

mat = rand(5); %# A 5-by-5 matrix of random values from 0 to 1

imagesc(mat); %# Create a colored plot of the matrix values

colormap(flipud(gray)); %# Change the colormap to gray (so higher values are

%# black and lower values are white)

textStrings = num2str(mat(:),'%0.2f'); %# Create strings from the matrix values

textStrings = strtrim(cellstr(textStrings)); %# Remove any space padding

[x,y] = meshgrid(1:5); %# Create x and y coordinates for the strings

hStrings = text(x(:),y(:),textStrings(:),... %# Plot the strings

'HorizontalAlignment','center');

midValue = mean(get(gca,'CLim')); %# Get the middle value of the color range

textColors = repmat(mat(:) > midValue,1,3); %# Choose white or black for the

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值