find a value between two points
33 次查看(过去 30 天)
显示 更早的评论
Hey everyone,
I have the following case : (picture linked to the tocpic).
Let's suppose that i have two points with their value on y-axis equals to -20.5 and -19.5. I also know their value on x-axis (let's suppose 10^9 and 2*10^9). I don't have more points between them.
I would like to know : How can I find the value on X-axis of the point that have the value on y-axis equal to -20.
If it's not understandable, I hope the picture linked to it will be helpful !
Thanks you very much !
2 个评论
Mathieu NOE
2021-9-15
hi
seems you want to have this intermediate point from a curve that passes through the 2 points. have you tried to create this curve or a approximation (fit) of it ? then you can pick anypoint from this curve.
otherwise you could do simple interpolation, but with only two input points this would be limited to a simple linear interpolation , which is not what your picture says.
采纳的回答
Star Strider
2021-9-15
Example —
x = linspace(0, 50);
y = 30*(1-exp(-0.1*x));
f = @(x) 30*(1-exp(-0.1*x));
x_20 = interp1(y, x, 20) % From Data
f_20 = fzero(@(x) f(x)-20, rand) % From Function
figure
plot(x, y)
grid
hold on
plot(x_20, 20, '+r')
plot(f_20, 20, 'xg')
hold off
.
4 个评论
更多回答(1 个)
KSSV
2021-9-15
Read about interp1. If you have curve data as (x,y), at the point xi you can seek the value using:
yi = interp1(x,y,xi)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!