How can I get CurrentPoint to display the coordinates within a figures axes rather than the coordinates of the whole figure itself.

18 visualizzazioni (ultimi 30 giorni)
Hi Everyone,
I'm totally new to matlab so please bear with me.
I've created a GUI using GUIDE which converts and plots data from .BIN files (not important but just to give context) and I want to be able to view the cursors current position relative to the axes scale.
I've managed to get the cursor position relative to the figure window by using
new_point = get(handles.figure,'CurrentPoint');
set(handles.editbox,'String',new_point)
but since the axes don't have a 'CurrentPosition' nor a callback for 'WindowButtonMotionFcn' I can't seem to get values relative to my axes.
Is the only way to get around this to multiply the 'CurrentPosition' result (in my case 'new_point') by a vector equation which corresponds to the axes I've created, or is there another way to get around this?
In an ideal world I would be able to use DataCursor but unfortunately I'm using MATLAB version 6.1.
I'll be ever so grateful for any insight anyone could lend on this,
Thanks,
Rosie

Risposta accettata

Rosie
Rosie il 8 Ago 2012
Use
[x,y] = ginput(1);

Più risposte (2)

Simon Thalén
Simon Thalén il 19 Giu 2015
Im using get(handle,'CurrentPoint') within my own callback for buttonpress so i really don't want to use ginput..
I found out that when i replaced my handle for axes with simply gco it gave me the correct coordinates. I.E coordinates on the format of my axes if that makes any sense.
So for anyone having the same problem as Rosie try that

William Chamberlain
William Chamberlain il 12 Apr 2018
gcf_currentpoint = get(gcf, 'CurrentPoint')
gives the pixel coordinates
axes_handle = gca
pt = get(axes_handle, 'CurrentPoint')
gives the relative position inside the axes (top right is 1,1 - bottom left is 0,0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by