Extracting Multiple X values for a certain Y value from a plot?
2 次查看(过去 30 天)
显示 更早的评论
I need to find the value of time at all the crests and troughs of the displacement (at displacement =pi/4=0.7854), i.e, Y value is constant
for the following plot (which consists of two curves)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/426218/image.png)
the code i used is:
tspan = 0:0.01:20;
a=pi/4;
b=0;
x0 = [a; b];
[t1,x] = ode45(@pend_l,tspan,x0);
X1 = x(:,1);
X2 = x(:,2);
y0 = [a ; b];
[t2,y] = ode45(@pend_n,tspan,y0);
Y1 = y(:,1);
Y2 = y(:,2);
plot(t1,X1); %linear disp vs time, i.e, red plot
xlabel('Time (s)');
ylabel('Displacement (rad)');
hold on;
grid on;
plot(t2,Y1); %nonlinear disp vs time, i.e, blue plot
0 个评论
回答(1 个)
Ameer Hamza
2020-11-24
See this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections. You can define a straight line at y = constant and find the intersection between the line and your curves.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!