Interp1 error: Can someone please help.

4 次查看(过去 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?

采纳的回答

Wayne King
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.
  2 个评论
Bedanta
Bedanta 2012-9-20
how do I rectify this issue with precision?
I seem to have expected values for the datevec.
Bedanta
Bedanta 2012-9-20
Another doubt is that, the same command works on a previous version of my raw matrix where I had few more rows. But I am unable to narrow it down to what is different in the new matrix that causes the commands to fail

请先登录,再进行评论。

更多回答(1 个)

Markus Schmidt
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)),:);

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by