Problem using interp1 with a sharp change in the data
이전 댓글 표시
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
Mil Shastri
2019년 11월 18일
편집: Mil Shastri
2019년 11월 18일
Hi, you can check out the documentation of the interp1 function https://www.mathworks.com/help/matlab/ref/interp1.html
If you choose to use the approach vq = interp1(x,v,xq,method) , you can define the method that best refects the type of interpolation you are interesed in.
Also xq is th enumber of query points, so the larger the number, the more the points that will be used to interpolate (you can think of it as using more points for averaging) and hence you might get a less 'sharp' interpolation.
Eg,
%%taken from documentation
x = 0:pi/4:2*pi;
v = sin(x);
xq = 0:pi/16:2*pi;
%Interpolate the function at the query points and plot the result.
figure
%making the interpolation smoother
xq=xq*10;
vq2 = interp1(x,v,xq,'spline');
plot(x,v,'o',xq,vq2,':.');
xlim([0 2*pi]);
title('Spline Interpolation');
Jaime De La Mota Sanchis
2019년 11월 18일
Guillaume
2019년 11월 18일
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).
Mil Shastri
2019년 11월 18일
Thanks for clarification. What will also help is a clear description of what you want the output to look like.
Jaime De La Mota Sanchis
2019년 11월 18일
답변 (1개)
Steven Lord
2019년 11월 18일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!