1D griddedInterpolant of a vector of query points.

2 visualizaciones (últimos 30 días)
Maverick
Maverick el 22 de Abr. de 2020
Editada: Matt J el 8 de Mayo de 2020
Is it possible to use griddedInterpolant in a vectorized form? I have a vector function f sampled over time domain t which must be interpolated.
The following relations follow: size(t,2) = size(f,2) and size(t,1) < size(f,1).
Here is a simple example that works with interp1 and spline.
Is there a way to achieve the same outcome with griddedInterpolant?
% works!
t = linspace(0,5,100);
f = [sin(t); cos(t)]; % define some vector function
pp = interp1(t, f', 'pchip','pp'); % warning, Matlab suggests to use griddedInterpolant
% or
pp2 = spline(t, f);
% This throws an error:
F = griddedInterpolant(t, f); % ! how to make use of this function with a vector function? !
f = sin(t) % now f is a scalar function
F = griddedInterpolant(t, f); % now this line works
  2 comentarios
Star Strider
Star Strider el 22 de Abr. de 2020
I get no errors (R2020a) with everything except the griddedinterpolant call (that I did not run). What do you want to do? What result do you want?
Maverick
Maverick el 22 de Abr. de 2020
Editada: Maverick el 22 de Abr. de 2020
Please, try to run griddedinterpolant command since it does produce an error (at least on R2017b). I must interpolate a 1D vector function (i.e. a function, that has stacked multiple values at a time instant). Variable f above is a simple example of a 2-vector function. This code works with interp1 or spline, as I showed in the example. However, I want to use griddedinterpolant and check if it is more efficient thatn those counterparts.
I know that presented syntax would work if size(f,1) was equal to 1, however, I don't know how to apply griddedInterpolant to a vector function, or whether it is even possible?

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 8 de Mayo de 2020
Editada: Matt J el 8 de Mayo de 2020
One way:
rows=1:2;
gI= griddedInterpolant({rows,t},f);
F=@(t)gI({rows,t});
>> F(3)
ans =
0.1411
-0.9897
Another way:
Fsin = griddedInterpolant(t, sin(t));
Fcos = griddedInterpolant(t, cos(t));
F=@(t)[Fsin(t);Fcos(t)];

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by