Plot continuous line based on user input
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aarav Shah
am 26 Nov. 2019
Beantwortet: Adam Danz
am 27 Nov. 2019
So I have a user click on the plot.
The code is as such: [xClic,yClic]=ginput(1);
How would I plot a line with a slope of one that goes infinitely until it hits the y axis. The start of the line should be the [xClic,yClic].
Any ideas? All help appreciated.
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 27 Nov. 2019
"How would I plot a line with a slope of one that goes infinitely until it hits the y axis"
I'm interpreting this as a line that extends from point (xClic,yClic) to the point that crosses the vertical line at x=0, with a slope of 1.
If that interpretation is correct, all you need to so is compute the y intercept.
% Point where user clicked
xClic = -2;
yClic= -5;
% Plot that point
plot(xClic, yClic,'bo')
xlim([-8 8])
ylim([-8,8])
hold on
% Compute y intercept for slope of 1
b = yClic-1*xClic;
% Plot the line between the click point and the y intercept
plot([xClic,0],[yClic,b],'b-')
A similar approach is to use refline() but that extends to your axis limits.
h = refline(1,b)
h.LineStyle = ':'
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!