## Get pixel of data coordinate

### Jonathan Mole (view profile)

on 29 Jul 2019
Latest activity Commented on by Jonathan Mole

### Jonathan Mole (view profile)

on 3 Aug 2019
I want to get the pixel value of a selected data point on a figure (.m matlab figure).
For example in figure; plot(2,2,'*')
what is the pixel associated with the (2,2) data point?
I do not wish to use imtool since I generate many figures inside the same code and I wish to put a '\rightarrow' at the (2,2) data point.
And, the axis changes for these figures so the (2,2) data point also changes its pixel values in my code.
Cheers

R2018a

### Image Analyst (view profile)

on 30 Jul 2019

You can use getpixel() to get the pixel value, or use indexing, like pixelValue = yourImage(y, x, :).
To put an arrow into the overlay, use annotation().

Jonathan Mole

### Jonathan Mole (view profile)

on 30 Jul 2019
Hi,
is getpixel a matlab function? And for the part pixelValue = yourImage(y, x, :), this does not seem to work. Maybe because the figure is a .m format?
Image Analyst

### Image Analyst (view profile)

on 30 Jul 2019
Maybe it's imgetpixel(). Try that. But actually, I just use indexing all the time.
A figure cannot be an m-file. It can be generated by an m-file, but cannot be an m-file itself. You either
1. used image(), imagesc(), pcolor(), or imshow() to display a digital image, OR
2. you plotted something with plot(), scatter(), surf(), bar(), etc.
So, which was it?

### Jonathan Mole (view profile)

on 31 Jul 2019

imgetpixel does not work... neither does pixelvalue.
I used plot as for the example described above plot(2,2,'*')

Image Analyst

on 31 Jul 2019
Jonathan Mole

### Jonathan Mole (view profile)

on 3 Aug 2019
I think that the correct answer to this would be: if you do not know the answer, it would be rather preferable not to comment.