Problem using interp1 with a sharp change in the data
Mostrar comentarios más antiguos
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 comentarios
Mil Shastri
el 18 de Nov. de 2019
Editada: Mil Shastri
el 18 de Nov. de 2019
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
el 18 de Nov. de 2019
Guillaume
el 18 de Nov. de 2019
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
el 18 de Nov. de 2019
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
el 18 de Nov. de 2019
Respuestas (1)
Steven Lord
el 18 de Nov. de 2019
0 votos
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.
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!