Display values of each element in imagesc
100 次查看(过去 30 天)
显示 更早的评论
I have a 16 x 16 array of values between 0 and 40. I would like to display this using imagesc, but I would also like to superimpose the decimal value of each element in its corresponding square. I would end up with a 16 x 16 array of colored (per mapping) squares, each with the square's value in decimal text. Is there an easy / convenient way to do this?
If there was a version of "disp" that I could apply to a figure after imagesc that might work, but I can't find one.
Thanks
0 个评论
采纳的回答
更多回答(1 个)
Walter Roberson
2021-10-11
Is there an easy / convenient way to do this?
No. But it can be done.
Note: there is no one text font color that will contrast nicely with all of the underlaying colors -- not unless you colormap() in a different colormap such as copper() that you can find a simple text color for.
A = randi([0 40], 16, 16); %sample data
[R, C] = ndgrid(1:size(A,1), 1:size(A,2));
R = R(:); C = C(:) - 1/4;
%rows are Y values, columns are X values !
imagesc(A)
vals = A(:);
mask = vals <= 20;
text(C(mask), R(mask), string(vals(mask)), 'color', 'w')
text(C(~mask), R(~mask), string(vals(~mask)), 'color', 'k')
A
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!