How can i exactly click on a point that has drawed on a plot using ginput ?

Hello!
My problem is:
I have had some points on a figure use plot command with this command lines:
figure;
hold on
x = [1 2 3 4 5]
y = [7 8 9 10 11]
for i = 1:5
plot(x(i),y(i),'*','MarkerSize',12,'Color','r')
end
% Retrieve coordinate of points
[xx,yy] = ginput(length(x))
Now, I want to use ginput() or getPoint() to click on anypoint in the figure.
But, It is difficult to click on a point exxactly.
For example, i want to click on first point that has x = 1 and y = 7. But, when i trying to click on it to retrieve its coordinate, what matlab returns is that i expect (x = 1,y = 7)..
How can i do?????
Please help me!
Thank you so much!

4 Comments

What is the problem? You click on the point at x=1 and y=7 and Matlab returns, what you expect? Sounds fine.
Yes. My problem is:
First, i draw two points on a figure. point 1 has x = 1,y = 7; point 2 has x = 2,y = 8.
And now,
I want to draw a line that contains these points (point 1 and point 2). But, before i draw, i want to use ginput() to click on point 1 and point 2 to get again coordinate of two points,
figure;
hold on
x = [1 2 ]
y = [7 8 ]
for i = 1:2
plot(x(i),y(i),'*','MarkerSize',12,'Color','r')
end
% Retrieve coordinate of points
[xx,yy] = ginput(2)
line(xx,yy) % draw line
But, when i use ginput() to click on point1 and point 2, i can not click on right point 1 and point 2 to get again x = 1, y = 7 for point 1 and x = 2, y = 8 for point 2
Why not? Why can't you click on the wanted points? Which problem do you want to solve? To determine the point nearest to the location you click on? To do this, clicking on a specific location is not needed. Why do you think clicking on an exact location is useful? Remember that the point [1.000000000000000, 7.000000000000000] might not be exactly represented by a pixel, but of course you can select a single pixel only. This means that clicking on a specific coordinate is not possible or at least extremely hard using a massive zooming. So why do you want to do this at all?
yes.
if i draw a line that contains two points, for example, (4,5) and (10,5). that means i created a horizontal line has 6 units ( for example meter). but if i click on point (4.05,5.1) and point (10.07,5.02) when use ginput(), for example, so, the line that created is having a difference in length from the line i want to create.
and, why do i want to do this?
yes. actually, i‘m building a GUI.
i have two GUIs. main GUI and subGUi. there is a axes on main GUi (gui1) and there are edittext and push button on sub gui( gui2).
when i click on push button on gui2, matlab will draw two points on axes on GUI1 with data (coordinates of points) gets from edittext. and then, i want to draw a line contains two points that drawed previously on axes.
i mean i want to use ginput() click on point 1 and then click on point 2. after click on point 2, matlab will draw a line contains two points
do you understand that i wrote.
so sory. please forgive me
because my english is not well

Sign in to comment.

 Accepted Answer

Jan
Jan on 11 Jan 2019
Edited: Jan on 11 Jan 2019
Considering my comment, my answer is:
You can't. You would need a massive zooming to try to do so. Remember, that [1.000000000000000, 7.000000000000000] is not necessarily represented by a pixel on the screen, but selecting a pixel is the maximum achievable resolution.
The solution is to adjust your needs: What about finding the point nearest to the selected pixel?
What about using the ButtonDownFcn of the drawn points instead of ginput?

4 Comments

of course. i thought to using round() for output of ginput(). for example, i input two points as above. and i use ”if end” to solve. i will zoom maximum to click on nearest point with two points so that click on points has coordinate ( for example, 4.0501,5.01). may be more small. and i round to 4.0 and 5.0.
sory. i don’t know about ButtonDownfuc.
colud you explain to me?
do you know AutoCAD software. when you turn on osnap. you can grab exactly point you want
@Jan
Can you please explain about ButtonDownfcn briefly?
Is that an alternate for ginput?
The ButtonDownFcn is a property of the object e.g. created by plot or line. Example:
AxesH = axes;
LineH = line(1:10, rand(1,10), 'ButtonDownFcn', {@myCallback, AxesH});
function myCallback(LineH, EventData, AxesH)
disp(AxesH.CurrentPoint)
end

Sign in to comment.

More Answers (0)

Categories

Asked:

on 11 Jan 2019

Commented:

Jan
on 4 Nov 2019

Community Treasure Hunt

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

Start Hunting!