How to interpolate any vectors whose lengths don't match the time vector?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2014-7-11
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!