Changing the x,y axis values

Hi,
I have a figure of an image showing the pixel number in the x- and y-axis. I would like to display this in angle mrad instead. I know the angle size of one pixel from knowing the pizel size and the distance to light source.
How do I display the angle mrad, 0, 0.5, 1,5 etc in the axes instead of the pixel numbers 1, 2, 3?
Using 'image' to plot the image.

1 Comment

Happy PhD
Happy PhD on 24 May 2018
Edited: Happy PhD on 24 May 2018
I should probably mentioned,..
I don't know the size of the image I am plotting. I take out a small part of the image and display it. The size can vary from time to time, depending on the size of my object.
I also plot lines and stuff onto the image.

Sign in to comment.

 Accepted Answer

Adam
Adam on 24 May 2018
Edited: Adam on 24 May 2018
Set the XData (and YData if required) properties of your image, either when first creating it as e.g.
image( hAxes, 1:360, 1:200, myImage )
or afterwards as e.g.
hIm = image( hAxes, myImage );
hIm.XData = 1:360;
etc.
doc image properties
will take you to the help index page from which you can go to the first link which gives more details.
Note: hAxes there is your axes handle. If you aren't using one then you should! Don't get into the habit of plotting things without giving an explicit axes!

5 Comments

I see, what is 1:360 and 1:200? Thanks!
That was just an example of x data values and y data values. I used 360 just to hint at the idea of the x data being angles. In fact you can achieve the same effect by just setting
[1 360] rather than needing 1:360
if you image runs from angle 1 to 360 degrees.
The 1:200 was just totally abitrary for if you want to set your own range for the y axis too.
Note, whether you want to change the XData and YData like this or change the tick labels as in KSSV's answer will depend very much on if you need to interact with the image in different ways.
Changing XData means the axes limits will me e.g. 1 to 360 rather than 1 to pipxel size, so if you need to e.g. plot a line or something on top of the image you can give it your angle as x value. If you only change the labels the underlying axes limits will still be those of the image pixel size, you simply change what the axes labels show and nothing more.
If you never need to interact with the image requiring your angle information then changing the labels alone is fine.
Ok, Im sorry but Im lost. I think I need an simple example. I need to plot something ontop of this image.
This didn't work for me:
hIm = image( hAxes, myImage );
hIm.XData = 1:360;
and Im unsure what hAxes is,...
'Note: hAxes there is your axes handle. If you aren't using one then you should! Don't get into the habit of plotting things without giving an explicit axes!'
from my original post.

Sign in to comment.

More Answers (1)

From the handle to the image, eg:
hIm = image(myImage );
It is possible to access the handles of the axes by invoking,
hIm.Parent
The above axes handle can be used to redefine the ticks and ticklabels. For eg. the Yticklabels can be changed as,
hIm.Parent.YTickLabel = {'0', '0.5', '1', '1.5'};

Products

Release

R2015b

Community Treasure Hunt

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

Start Hunting!