views:

88

answers:

3

If I make a 4 pixel by 4 pixel image in Matlab using the image() command, it centers the tick marks in the middle of the pixels. I want the tick marks to be centered on the lower left corner of the pixel. Is there some way to do this?

A: 

You can specify x and y coordinates of the pixels and shift them by 0.5:

image([0.5,3.5],[0.5,3.5],magic(4))
Jonas
I tried that before, but it's still missing the tick for 0, and if it was side by side with a regular graph, it doesn't look as nice.
Wires
@Wires: this is strange. In the lower left corner, I get 0 for the x-axis, and 4 for the y-axis.
Jonas
+1  A: 

Try the following:

a = randi([0 255], [4 4]);
figure, imagesc(a), caxis([0 255])

b = zeros( size(a)+1 );
b(1:end-1,1:end-1) = a;
figure, pcolor(b), caxis([0 255]), axis ij

Note that I extended the matrix a because PCOLOR drops the last row/column

alt text alt text

Amro
A: 

I think this code will do what you want. It places tick marks only at the edges of the pixels:

A = ...;  %# Your 4-by-4 matrix
image([0.5 3.5],[0.5 3.5],A);      %# Pixel edges are at 0, 1, 2, 3, and 4
set(gca,'XTick',0:4,'YTick',0:4);  %# Place tick marks at 0, 1, 2, 3, and 4
gnovice