How to change the x axis label

6 views (last 30 days)
Ryan
Ryan on 31 May 2013
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.

Accepted Answer

Image Analyst
Image Analyst on 31 May 2013
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;

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 31 May 2013
xt=get(gca,'xtick')
new_xt=num2cell(linspace(4,6,numel(xt)))
set(gca,'xticklabel',new_xt)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!