Reputation: 21
I'm working on a project and am trying to be able to generate a very specific type of graphical output in MATLAB and am not sure how to do it:
First, I want to be able to take, say, a 3x3 matrix, and generate an image that's basically a 3x3 grid with the numbers which are the matrix entries in the appropriate spaces on the grid.
I also want to be able to assign arbitrary colours to different grid squares if possible.
Does anyone know a simple way to go about this?
Thank you!
Upvotes: 0
Views: 2937
Reputation: 61
a = reshape(1:9, 3,3)
imagesc(a)
grid on
text(1,1,'1', 'fontsize', 18)
set(gca, 'xtick', [0.5,1.5,3.5])
set(gca, 'ytick', [0.5,1.5,3.5])
grid off
try it. maybe it will help you.
Upvotes: 2
Reputation: 6115
You may want to check out the IMAGE or IMAGESC function. It takes a matrix as input and displays a grid, whereas each segment (or "pixel") corresponds to the respective matrix element.
E.g. try
imagesc( randn(3,3) )
IMAGESC scales the input values to 0 and 1 before displying (In contrast to IMAGE, which takes the values directly).
The mapping of numbers to colors is adjusted by the specific colormap (see COLORMAP function) of the axis.
Upvotes: 0