MATLAB Answers

0

Problem using interp1 with a sharp change in the data

Asked by Jaime De La Mota Sanchis on 18 Nov 2019 at 15:52
Latest activity Commented on by Jaime De La Mota Sanchis on 18 Nov 2019 at 17:33
Hello everyone.
I have a vector of data and I want to interpolate it using interp1. The problem is that there is a sharp increase in the values of the vector and the resulting graph does not reproduce the data propperly.
Is there a way to make the interpolated data reproduce the sharp jump propperly?
I will attach a figure where my issue is displayed.
Any answer is appreciated.
Thank you very much.
Jaime.

  5 Comments

It's difficult to know what's wrong when we don't have the code you're using nor the input data, so please attach both (not screenshots which we can't use for testing/diagnostics).
Thanks for clarification. What will also help is a clear description of what you want the output to look like.
The code I use is simply
Tinterp=interp1(time,T,t,'spline');
being T a vector which values can be seen in the attached T.txt; the same thing happens with time.
What I do next is plot together T-time and Tinterp and t as
figure
plot(t, Tinterp)
hold on
plot(time, T)
legend('interpolated','original')
title('T Spline')
I hope this clarifies what I am attempting to do.

Sign in to comment.

Products

1 Answer

Answer by Steven Lord
on 18 Nov 2019 at 17:20

Try using ischange to detect these sharp changes in your data and interpolating using only data in the same "piece" of your curve (where pieces are delimited by the ends of your data sets and the change points) as the points for which you want the interpolated value.

  0 Comments

Sign in to comment.