Interp1 error: Can someone please help.

3 vues (au cours des 30 derniers jours)
Bedanta
Bedanta le 20 Sep 2012
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?

Réponse acceptée

Wayne King
Wayne King le 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 commentaires
Bedanta
Bedanta le 20 Sep 2012
how do I rectify this issue with precision?
I seem to have expected values for the datevec.
Bedanta
Bedanta le 20 Sep 2012
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

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by