How to set axis values using a vector.

조회 수: 8 (최근 30일)
Perron Jonathan
Perron Jonathan 2012년 8월 9일
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
Jan
Jan 2012년 8월 19일
What does "the values are not the good one" mean? Did you explain explicitly, what you want to achieve?

댓글을 달려면 로그인하십시오.

채택된 답변

Sven
Sven 2012년 8월 19일
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개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by