How to find a intersecting point in a GUI?

조회 수: 2 (최근 30일)
Ries Postma
Ries Postma 2020년 1월 16일
편집: Adam Danz 2020년 1월 20일
Hello,
I've made a app which plots a projectile motion and a fixed line at y=2. See figure below.
Schermopname (47).png
I wish to mark the intersection point, and show the x-coordinate. Unfortunatly I don't know how.
My question is, how can I mark the intersecting point (and preferably show its x-coordinate)?
I've included the code to make te plot.
greetings,
Ries
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
%formula and variables
x0 = 0;
y0= app.Y_0EditField.Value;
v=app.VmsEditField.Value;
angle=app.AngledegEditField.Value*(pi./180);
g=9.81;
t= 0:0.0001:3;
x=x0+v*cos(angle)*t;
y=y0+v*sin(angle)*t-(g*t.^2)/2;
%Hold when 'hold'button is pressed
if app.holdButton.Value==0
hold(app.UIAxes, 'off')
else
hold(app.UIAxes, 'on')
end
%plot graph on GUI
plot(app.UIAxes,x,y)
yline(app.UIAxes,2);
%axis appearance
app.UIAxes.XMinorGrid = 'on'
app.UIAxes.YMinorGrid = 'on'
app.UIAxes.XGrid = 'on'
app.UIAxes.YGrid = 'on'
app.UIAxes.XLim = [0 4];
app.UIAxes.YLim = [0 6];
end

답변 (1개)

Adam Danz
Adam Danz 2020년 1월 17일
편집: Adam Danz 2020년 1월 20일
I'm a big fan of this file exchange submission: [x0,y0] = intersections(x1,y1,x2,y2).
You can provide the (x,y) coordinates of the two lines and it will provide the intersection point.
"how can I mark the intersecting point (and preferably show its x-coordinate)"
hold on
plot(x0,y0,'m*')
or
xline(x0,'-k','xIntersection')
yline(y0,'-k','yIntersection')

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by