Interp1 error: Can someone please help.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Wayne King
am 20 Sep. 2012
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 Kommentare
Weitere Antworten (1)
Markus Schmidt
am 17 Apr. 2013
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 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!