MATLAB Answers

find a value between two points

4 views (last 30 days)
dsq dq
dsq dq on 15 Sep 2021
Commented: Star Strider on 15 Sep 2021
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 Comments
dsq dq
dsq dq on 15 Sep 2021
Hi,
This curve is already created I have like ~ 8000 points, so I cannot create it. I looked for the interpolation function but I didn't get how this could help me because I would like to have the exact value for -20 ...

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 15 Sep 2021
Use interp1 or fzero on a monotonically-increasing (or decreasing) curve such as that.
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
x_20 = 10.9885
f_20 = fzero(@(x) f(x)-20, rand) % From Function
f_20 = 10.9861
figure
plot(x, y)
grid
hold on
plot(x_20, 20, '+r')
plot(f_20, 20, 'xg')
hold off
.
  4 Comments
Star Strider
Star Strider on 15 Sep 2021
As always, my pleasure!
.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 15 Sep 2021
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)
  1 Comment
dsq dq
dsq dq on 15 Sep 2021
Hey thanks ! star strider explained it juste below ! thanks for your help

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by