How to set axis values using a vector.

Asked by Perron Jonathan on 9 Aug 2012
Latest activity Answered by Sven on 19 Aug 2012

Dear all, I actually got a problem to plot the correct values of the axis on my figures. Basically, I got a 2048x2048 matrix containing intensities which I plot using the imagesc function. Then the values of my axis are in pixels, not the unit I would like to use... I have calculated in two others matrices (of the same size) the values of the pixels in the unit I want for x and y, but I do not see how to combine these matrices with my figure. When I reduced the matrix to a vector of 2048x1 and I use set(gca,'XTickLabel', X), the values I got are not the good one. Do anyone got an idea ?

1 Comment

Jan Simon on 19 Aug 2012

What does "the values are not the good one" mean? Did you explain explicitly, what you want to achieve?

Perron Jonathan

Products

1 Answer

Answer by Sven on 19 Aug 2012
Accepted answer

Hi Jonathon,

I think your problem has one of the following solutions:

1. Your image is a perfect "grid", but you want to specify the xticks/yticks when you view it, rather than have it based on pixel number:

% Just get an image to test with
I = imread('rice.png');
% Get some xy vectors
xVec = linspace(50, 100, size(I,2));
yVec = linspace(10, 30,  size(I,1));
% Show the image two different ways
figure, imagesc(I);
figure, imagesc(xVec,yVec,I)

The first figure there will be what you have at the moment (the image scaled by pixel numbers). The second figure will be scaled by the two vectors you specify. I think that this is what you want.

2. An imperfect grid.

There is a little quirk with the image()/imagesc() function that it always assumes your image is a perfect grid. In other words, it assumes that diff(xVec) and diff(yVec) in the above example will each give a row of identical numbers. If you don't want them perfectly spaced, there is a file exchange entry called uimage() which will help you.

3. A morphed image.

I don't think this is what you're looking for... but let me know if answer 1 or 2 don't quite do what you want to do.

0 Comments

Sven

Contact us