필터 지우기
필터 지우기

Interp1 error: Can someone please help.

조회 수: 1 (최근 30일)
Bedanta
Bedanta 2012년 9월 20일
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에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by