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 Center および File ExchangeDevelop 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