Using current points instead of ginput to get locations on axes

3 ビュー (過去 30 日間)
Jason
Jason 2017 年 10 月 3 日
コメント済み: Jason 2017 年 10 月 3 日
Hi. I am currently using ginput to select two points on an image to then draw a line. The problem is that my image is mainly black with white spots and the cross hairs for ginput are black, so its hard to use.
So after investigating I thought I could use the following
axes(handles.axes4); %my image is on axes4
cp = get(handles.axes4,'CurrentPoint')
x = cp(1,1)
y = cp(1,2)
plot(x,y,'ro'); drawnow;
The point I selected on is the red circle below at coordiantes 244, 605 on that axes. However, the returned values of cp are
cp =
1.0e+03 *
-1.2142 1.3601 5.6639
-1.2142 1.3601 0.0000
What do these cp values correspond to, I thought x = cp(1,1) and y = cp(1,2), but they don't seem to be.
Also is this the best way or is there another way?
Thanks Jason

採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 3 日
cp(2,:) is for the back points, which is more meaningful for 3D.
The values are in axes data units.
"The two points indicate the location of the last mouse click, unless there is a WindowButtonMotionFcn callback defined for the figure. If the WindowButtonMotionFcn callback is defined, then the points indicate the last location of the mouse pointer."
My speculation is that you do not have WindowButtonMotionFcn active and that your last click was to the left of the current mouse position.
  2 件のコメント
Jason
Jason 2017 年 10 月 3 日
So I would use something like this:
axes(handles.axes4)('WindowButtonDownFcn',@myMouseclickFunction)
Jason
Jason 2017 年 10 月 3 日
I think I've done it, I just put a waitforbuttonpress!!
w = waitforbuttonpress
if w == 0 %0 for mouse click, 1 for button press
disp('Button click')
cp = get(gca,'CurrentPoint')
x = cp(1,1)
y = cp(1,2)
plot(x,y,'ro'); drawnow;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by