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
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.
dsq dq
dsq dq 2021년 9월 15일
편집: dsq dq 2021년 9월 15일
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 ...

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2021년 9월 15일

0 개 추천

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

dsq dq
dsq dq 2021년 9월 15일
편집: dsq dq 2021년 9월 15일
Yes I see it's working. Just my function is a bit chaotic so it may cross the value (-20) several times. Is there a way to have the value of all the points ? Or need I to split the table ?
I am not certain what your function (or data) look like, so I can’t address it precisely. The best way to approach something like that is to subtract 20 from it, and then use interp1 at the zero-crossings:
x = linspace(0, 50, 250);
y = 20*(1-exp(-0.1*x)) + 5*sin(2*pi*x*15);
yfind = 20;
yz = find(diff(sign(y-yfind)));
for k = 1:numel(yz)
idxrng = max(1,yz(k)-2) : min(numel(x),yz(k)+2); % Index Range
xi(k) = interp1(y(idxrng),x(idxrng),yfind);
end
xi
xi = 1×4
18.4762 24.0158 33.6995 41.4991
figure
plot(x, y)
yline(yfind, '--r')
hold on
plot(xi, ones(size(xi))*yfind, 'sg', 'MarkerSize',10)
hold off
grid
legend('Data','Target Value','Interceptions', 'Location','best')
Experiment with my code and your (x,y) data.
.
dsq dq
dsq dq 2021년 9월 15일
Ok i see. thanks a lot !
Star Strider
Star Strider 2021년 9월 15일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2021년 9월 15일

0 개 추천

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

dsq dq
dsq dq 2021년 9월 15일
Hey thanks ! star strider explained it juste below ! thanks for your help

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

질문:

2021년 9월 15일

댓글:

2021년 9월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by