Matrix visualisation with coloured box and numbers
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I wonder if someone can please help me. I am trying to visualizes a NxM matrix by plotting each matrix entry as a colored square (box). The entry value itself should also be displayed. (Similar to a sudoku grid but with each number value being depicted by a colour as well).
Matrix = [1,2,3;4,3,2;1;4;2]
Matrix =
1 2 3
4 3 2
1 4 2
Thus I would like to plot this matrix as shown above.
Any help much appriciated. Thanks
0 commentaires
Réponses (2)
Matt Tearle
le 18 Avr 2011
imagesc and text. If it's like sudoku in that the range of values is fixed, use image and a custom colormap.
EDIT TO ADD: I realized that it's a bit more involved than I made it sound, so here's an example that makes it all pretty:
n = 4;
m = 5;
Amax = 7;
cmap = autumn(Amax);
A = randi(Amax,m,n);
figure
image(A)
colormap(cmap)
set(gca,'XTick',[],'YTick',[],'YDir','normal')
[x,y] = meshgrid(1:n,1:m);
text(x(:),y(:),num2str(A(:)),'HorizontalAlignment','center')
0 commentaires
Paulo Silva
le 18 Avr 2011
Following Matts answer here's one simple example
M=[1,2,3;4,3,2;1,4,2]
imagesc(M)
for a=1:3
for b=1:3
text(b,a,num2str(M(a,b)))
end
end
7 commentaires
Paulo Silva
le 23 Avr 2011
XTicks and YTicks are those numbers that appear usually below and on the left side of the axes, that code removes them, the YDir is the direction of the increment, close to the origin is the lowest value with the normal option, the reverse option makes the biggest value close to the origin of the axes.
You can have a better explanation at http://www.mathworks.com/help/techdoc/ref/axes_props.html
Matt Tearle
le 23 Avr 2011
To deconstruct the syntax: gca is a function that returns a handle to the current axes. So that line of code sets three properties of the current axes object (Paulo explained what they are very nicely) The x/ytick properties should be set to an array of values; [] is an empty array. Hence, you get no tick marks on the axes.
Voir également
Catégories
En savoir plus sur Geographic Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!