Interp1 using irregular data set

Like many newbs before me, I keep getting the "The grid vectors are not strictly monotonic increasing" error while using the interp1 function. Data set: Water quality data sampled daily at irregular times over approx 5 years. My 'x' variable is a datetime value consisting of MM/dd/yyyy HH:mm. 'Y' variable(double) = pH. 'xi'(datetime) = 15 minute interval over 5 years. What I don't understand is how to make 'x' increase monotonically when the actual data is irregular. Attached are my variables I imported. x = DateAndTime ; Y = pH at x ; xi = 15min interval from starting DateAndTime to ending DateAndTime.
Should this be treated as a 2-D scenario (x,y = date,time) or what am I missing to make this 1-D scenario work? Thank you for your time.
UPDATE:
yi = interp1(DateAndTime, pH, xi)
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 144)
F = griddedInterpolant(X,V(:,1),method);
Error in datetime/interp1 (line 109)
vq = interp1(x,v,xq,method);
issorted(DateAndTime)
ans =
1
UPDATE: Problem found in the original data. There were four data points that were entered incorrectly in the main excel file. Ie: 08/13/01 where it should have been entered 08/13/96.

2 件のコメント

Matt J
Matt J 2016 年 2 月 29 日
You should post the code where you call interp1 as well.
Michael McInenly
Michael McInenly 2016 年 2 月 29 日
As in the syntax (see update) or the actual code used by MATLAB?

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2016 年 2 月 29 日
編集済み: Matt J 2016 年 2 月 29 日

1 投票

The main problem, I would guess is that interp1 does not expect datetime input. After converting DateAndTime to something numeric, you should pre-sort it and pH correspondingly as below.
x=datenum(DateAndTime);
xi=datenum(xi);
if ~issorted(x)
[x,idx]=sort(x);
pH=pH(idx,:);
end
if any(diff(x)==0)
error 'The DateAndTime data is not strictly monotonic'
end
yi = interp1(x, pH, xi);

1 件のコメント

Michael McInenly
Michael McInenly 2016 年 2 月 29 日
Thanks for your help. Interp1 does allow for datetime value as long as 'xi' is the same value. I believe my problem lies in the original data set. I found four entries that were entered incorrectly. See my update above. Will reprocess my variables and try again!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

製品

質問済み:

2016 年 2 月 29 日

編集済み:

2016 年 2 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by