How to interpolate any vectors whose lengths don't match the time vector?

1 vue (au cours des 30 derniers jours)
Kelsey
Kelsey le 11 Juil 2014
Here is my code (which doesn't seem to work):
names = fieldnames(dataATI);
if length(names)>length(time)
names = interp1(names.time,names,time);
elseif length(names)<length(time)
names = interp1(names.time,names,time);
end
Should this work? Is here something basic I'm doing wrong? What can I do instead to make any parameters in the "dataATI" file, whose lengths don't match that of the time vector, match the length of the time vector? Obviously the goal is a generic code that detects which parameters don't match the correct length, and interpolates them in order to match the proper length.
Thank you so much, in advance!

Réponses (1)

Star Strider
Star Strider le 11 Juil 2014
You didn’t specify the error or what your code is doing that it should not be. I assume names.time and names are the same length. Your time variable does not have to be, but if its values are outside the range of names.time, you need to specify an interpolation method and use the 'extrap' option. If that is the problem (which usually returns NaN values for the out-of-range data), this may solve it:
names = interp1(names.time,names,time,'linear','extrap');
for one or both statements.

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by