How to find a intersecting point in a GUI?

2 次查看(过去 30 天)
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