Matrix visualisation with coloured box and numbers
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Matt Tearle
el 18 de Abr. de 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 comentarios
Paulo Silva
el 18 de Abr. de 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 comentarios
Paulo Silva
el 23 de Abr. de 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
el 23 de Abr. de 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.
Ver también
Categorías
Más información sobre Geographic Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!