MATLAB: How to change the x axis label

axesimage analysis

Hello!
I am plotting a matrix output using imagesc and my x-axis is labeled from 1-151 however I would like the x-axis labels to be between 4.5:.01:6 but still display the full contents of the image. How would I do the relabeling? Thank you in advance.

Best Answer

Setting tick labels won't do it because the first tick mark is not at the left edge of the image. You need to pass in x and y values into imagesc() and it will all work out fine:
% Read in sample image.
grayImage = imread('cameraman.tif');
% Determine how many rows and columns.
[rows columns] = size(grayImage);
% Determine scaling for the axes.
x = linspace(4, 6, columns);
y = 1:rows;
% Display image along with our custom axes tick marks.
imagesc(x, y, grayImage)
axis on;