Adding numeric values to imagesc

How do I display the actual numeric values of a matrix plotted using 'imagesc'? I would like to have a number displayed in each colored box, representing a value of row and column plotted using 'imagesc' function.

Réponses (3)

Image Analyst
Image Analyst le 31 Mar 2015

0 votes

4 commentaires

Tasi
Tasi le 31 Mar 2015
Modifié(e) : Tasi le 31 Mar 2015
Thanks Steve. If I have a matrix X, dimension 5x7, how do I use your function to get colored boxes with only the value of the matrix inside, not the RGB information? Is there a simple way to add a line to imagesc(X), so that this info would also be displayed?
Image Analyst
Image Analyst le 31 Mar 2015
What is the "value of the matrix inside" if it's not the gray level or RGB information? You cannot build this capability into imagesc() or imshow() since those are built-in functions that you don't want to mess with.
This is an example of my matrix:
-4.0257 -2.1029 -60.5863 -23.3115 -18.6019 -11.0004
-19.5928 -3.1193 -21.1400 -7.0992 -11.3980 3.7057
-3.8306 0.1967 0.5895 3.3293 -1.1123 -0.3119
3.9556 -2.1975 -6.3927 1.9462 4.3546 -0.9120
-2.8013 -5.6693 2.0827 -27.5794 -8.8464 -23.8637
Column 7
-83.9344
-86.2478
-39.9361
-30.2867
-29.6367
I would like these values to be displayed inside the squares I get when I use imagesc, but I am not sure if this can be done with that function.
Image Analyst
Image Analyst le 31 Mar 2015
imagesc() displays pixels. There is no way you can fit all of that into a single pixel and see it on your screen, not even with a microscope. The only way is to blow up the pixels to big patches like I showed you with the im2html program.

Connectez-vous pour commenter.

Tamar Regev
Tamar Regev le 27 Fév 2024

0 votes

Just use the text function:
M = [1,2,3;4,5,6;7,8,9];
figure
figure
imagesc([1:3],[1:3],M)
set(gca,'XTick',[1:3],'YTick',[1:3],'fontsize',20)
for i = 1:3
for j = 1:3
text(i,j,num2str(M(i,j)),'FontSize',20)
end
end
Steven Lord
Steven Lord le 27 Fév 2024

0 votes

This function didn't exist when the question was originally asked, but I suspect the original poster had something like heatmap (introduced in release R2017a) in mind.

1 commentaire

Tamar Regev
Tamar Regev le 27 Fév 2024
gotcha! Good thing that this function exists now :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Question posée :

le 31 Mar 2015

Commenté :

le 27 Fév 2024

Community Treasure Hunt

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

Start Hunting!

Translated by