Matlab interp1 function x-points for given y-points

조회 수: 13 (최근 30일)
Marathon_Mike
Marathon_Mike 2020년 10월 8일
댓글: Ameer Hamza 2020년 10월 12일
Dear Community Members,
Hopefully this finds you safe and well. Using interp1 to acquire x-points for given y-points does not seem to work. Data in this particular instance generated via a function however in reality it is experimental data.
%**main function
x=[3:0.1:6];
y=sin(x);
%***y-array for new x-values
y_array = [-0.9:0.005:0.1];
x_new = interp1(y,x,y_array);
figure
plot(x,y,'k+-',x_new,y_array,'rx-')
grid on
Resutant image see attachment.
Any help on how to extrapolate between current and next data opints would be appreciated.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 8일
Inverting nonlinear function using interp1() like this is not correct. Check the following code
%**main function
x=[3:0.1:6];
y=sin(x);
%***y-array for new x-values
y_array = -0.9:0.005:0.1;
interp_x = @(xq) interp1(x, y, xq);
x_new = fsolve(@(xq) interp_x(xq) - y_array, 3+rand(size(y_array)));
figure
plot(x,y,'k+-',x_new,y_array,'rx-')
grid on
  댓글 수: 4
Marathon_Mike
Marathon_Mike 2020년 10월 11일
Dear Ameer,
Thank you once again for all your help. In the end decided to write a script to trim the data as I realised I did not need the second part of the curve to reach my ultimate solution. This is effectively cheating by turning the non-linear function into a linear one (only one data point for a given y-value).
Thanks,
Mike
Ameer Hamza
Ameer Hamza 2020년 10월 12일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by