How to change axis scale on imagesc in Matlab

9.4k views Asked by At

I have a 15x15 image of a grid of numbers which I have shown using imagesc. However, the axis goes up to 450 in both directions, when I only want it to go up to 15. I tried:

axis/30;

But that doesn't do anything? All I want to do is divide the x and y axes by 30!

1

There are 1 answers

2
nkjt On

The problem is, I presume, that although your image shows 15 numbers along in each axes, the total size of your image in pixels is 450 x 450 - and this is what imagesc is using.

So, what you really have is an image with 15 x 15 blocks of 30 x 30 pixels. You can set the axes ticks and labels manually using XTick and XTickLabel:

atick = 15:30:415; %assuming you want the ticks in the centre of each block
set(gca,'XTick',atick);
set(gca,'XTickLabel', 1:15);
set(gca,'YTick',atick);
set(gca,'YTickLabel', 1:15);