Color a grid by using an intensity matrix
Mostrar comentarios más antiguos
Hi all! I need to color a grid according to the values of a specific matrix. In particular, I have a 5x5 matrix representing an intensity value (from 0 to 1) and each value A(i,j) of this matrix is related to a specific cell in the grid. The grid goes from 0 (meters) to 100 (meters)---> 0:20:100 for both axes. Thus, each 20m x 20m cell should have a color according to the matrix described above. I tried with pcolor(), imshow(), imagesc() and so on, but with bad results.
Can you help me? Thanks in advance!!! Giulio (Sapienza University of Rome)
Respuesta aceptada
Más respuestas (4)
julio@sapienza
el 29 de Mzo. de 2011
0 votos
1 comentario
Matt Tearle
el 29 de Mzo. de 2011
The first problem is easily fixed with "axis xy"
The colormap is irrelevant if you are using a true-color image (which is what my first solution does). By making all three planes of the image equal to z, you make a grayscale image. If you want some other color scheme, you'll have to work out how to make the 3-D array. For example
image(x,x,cat(3,0*z,0.8*z,z))
But it might just be easier to use the second approach I showed.
julio@sapienza
el 29 de Mzo. de 2011
0 votos
julio@sapienza
el 30 de Mzo. de 2011
0 votos
2 comentarios
julio@sapienza
el 30 de Mzo. de 2011
Matt Tearle
el 30 de Mzo. de 2011
Not a stupid question, but glad you figured it out. For anyone else out there: the point is that image centers the pixels on the axis values, hence the x values have to be the *centers* of the squares, not the edges.
julio@sapienza
el 31 de Mzo. de 2011
0 votos
8 comentarios
Matt Tearle
el 31 de Mzo. de 2011
Can you explain the problem more? Do you get a surface, but it's only 9x9 instead of 10x10? If so, what are the values in my_matrix?
julio@sapienza
el 31 de Mzo. de 2011
julio@sapienza
el 5 de Abr. de 2011
Matt Tearle
el 5 de Abr. de 2011
I think this is just a confusion about vertices versus faces of a surface plot. The values in the matrix are plotted as the vertices of the surface. Look along the leading edge of the plot and you'll see there are five corners. The patchwork in between, however, will have four patches that interpolate between the corners.
If you do imagesc(matrix) instead, you'll see a 5-by-5 grid of color patches, centered at the index values.
julio@sapienza
el 18 de Abr. de 2011
Walter Roberson
el 18 de Abr. de 2011
surf() data data and set the FaceColor property to 'texturemap'. You might also want to set the EdgeColor to 'off'
julio@sapienza
el 19 de Abr. de 2011
Matt Tearle
el 19 de Abr. de 2011
mesh(A,'FaceColor','texturemap','EdgeColor','none')
But I'm not sure that's what you're referring to. Can you explain what you'd like to see? Something more like this, perhaps?
bar3(A)
Categorías
Más información sobre Color and Styling en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!