필터 지우기
필터 지우기

Display values of each element in imagesc

조회 수: 132 (최근 30일)
Peter Fraser
Peter Fraser 2021년 10월 10일
댓글: Peter Fraser 2021년 10월 11일
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

채택된 답변

Chunru
Chunru 2021년 10월 11일
c = randi([0 40], [16 16]);
heatmap(c);
colormap(jet(512))

추가 답변 (1개)

Walter Roberson
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
A = 16×16
28 33 29 4 1 22 13 4 7 6 16 27 34 39 7 11 40 14 37 8 14 25 10 12 6 40 0 40 27 28 29 21 6 3 16 31 35 3 31 23 7 18 40 19 39 2 7 6 15 36 7 6 1 5 18 33 27 25 22 14 14 8 16 38 27 7 39 37 11 15 28 1 4 32 8 37 7 38 29 32 0 3 32 34 10 9 1 26 17 17 19 5 15 16 6 9 37 4 13 10 34 23 29 37 36 16 19 26 4 5 19 37 14 23 32 15 5 11 26 37 4 3 14 22 22 27 5 21 6 33 16 13 31 23 25 37 33 1 14 5 0 21 6 18 22 2 21 15 11 25 1 18 14 23 9 19 8 19 17 6
  댓글 수: 1
Peter Fraser
Peter Fraser 2021년 10월 11일
Thanks. I was trying something similar, but it looks like the heatmap might be ideal for my needs.

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

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by