Display values of each element in imagesc
조회 수: 97 (최근 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!