Interp1 error: Can someone please help.
3 次查看(过去 30 天)
显示 更早的评论
I have a time series matrix that is not evenly spaced in time.
I have used the following commands to re-sample it with constant time increment (60sec increment). This command works. I have checked the datevector and the time values are incrementing every minute
New 1min sampled time series
downsampled_T= datenum(y0,m0,d0,h0,min0,(s0:60:s0+du))';_
Original timeseries in datenum
oldT=datenum(T);
Interpolation of original values
sparseX=interp1(oldT,D1_position(:,7),downsampled_T);
I get the following error: Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.
Any ideas why? My datevec seems to be incrementing evenly. But my datenum seems to be not?
0 个评论
采纳的回答
Wayne King
2012-9-20
With the precision that you have it seems that your oldT vector is not monotonic.
For example:
X = 1:9;
X = [X 9];
Xnew = 1:0.01:9;
y = randn(9,1);
ynew = interp1(X,y,Xnew);
gives that error because X(end) and X(end-1) are the same value.
更多回答(1 个)
Markus Schmidt
2013-4-17
I had a similar problem. Handling with a big dataset (where x is the time) I experienced same behaviour. I figured out a solution. Even though I applied 'unique' to my data matrix, some of the entries are 'not unique' regarding subtracting them (which is used for linear interpolation I guess.) So I applied the following algorithm to my data:
% Create matrix with dataset of properties to be interpolated (northing,
% easting, heading, velocity)
% ts_interp = test_series(isnan(test_series(:,2)),:);
ts_interp = unique(test_series(isnan(test_series(:,2)),[1 9 10 11 12]),'rows');
% For interplation, the function unique is not sufficient to delete enough
% entries. The time data will be checked for differences of 0, which
% depends on the machine precision.
delta = diff(ts_interp(:,1));
nodiff = find(delta == 0);
for k=1:length(nodiff)
ts_interp(nodiff(k),1) = NaN;
end
ts_interp = ts_interp(~isnan(ts_interp(:,1)),:);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!