How can I do 1-D interpolation with INTERP1 to find the nearest value to the left of the point (i.e. a zero-order hold curve) in MATLAB?
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 16 de Ag. de 2012
Editada: MathWorks Support Team
el 6 de Feb. de 2015
I want to do 1-D interpolation such that the interpolated value for a given point will be equal to the value of the point which is closest and on the left (i.e., smalller than the given point) of the data set. 'Nearest' method of INTERP1 function does not work as I want since the nearest point might be to the right of (i.e., larger than) the given point.
Respuesta aceptada
MathWorks Support Team
el 18 de Oct. de 2013
The easiest and probably fastest way to achieve that is to use histc respectively histcounts.
Code example:
% create some example data
x=linspace(0,10,100);
y=sin(x);
% those are the query points
xi=linspace(1,9,50);
% use histcounts to get the locations
% of the nearest left neighbours
[~,~,bin]=histcounts(xi,x);
plot(x,y,'b*')
hold on
plot(xi,y(bin),'r*')
Note that you would have to add some guard when interpolating data points outside the range of x.
1 comentario
John D'Errico
el 25 de Feb. de 2014
I'd strongly suggest using histc instead of the loop and find here.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!