How to interpolate any vectors whose lengths don't match the time vector?
1 view (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Star Strider
on 11 Jul 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.
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!