interp1 - error grid vectors must contain unique points

Dear All,
In my script I have two date arrays, where one is larger then the other. I am trying to determine the absolute time difference in hours between the timestamp from dataset 1 and the nearest date of dataset 2.
I use function interp1(x, y, xq, 'nearest'), and run into error message saying; 'The grid vectors must contain unique points'.
Code:
BuoyTimeNearest = abs(hours(Date - interp1(DateBuoy, DateBuoy, Date, 'nearest')));
Where Date and DateBuoy are both datetime arrays, Data = 133191 x 1, and DateBuoy = 13253 x 1.
I have plotted the data against array with step 1, and cannot find any duplicate points.
Date (Just datetime at 0.5hr interval)
DateBuoy (some missing datetimes but no duplicate values).
If I change the code to include unique:
BuoyTimeNearest = abs(hours(Date - interp1(unique(DateBuoy), unique(DateBuoy), Date, 'nearest')));
It does work, but run into trouble further along the script. And had been using the script for a while without any issues before.
Pleased to hear your suggestions.
Thanks!

6 件のコメント

Adam
Adam 2019 年 4 月 12 日
編集済み: Adam 2019 年 4 月 12 日
You say DateBuoy contains no duplicate values but there are numerous places on your plot where it looks flat, though obviously just from a plot it is impossible to tell if the values at either end of the flat section are truly identical or just very similar.
Wessel ter Laare
Wessel ter Laare 2019 年 4 月 12 日
編集済み: Wessel ter Laare 2019 年 4 月 12 日
Hi Adam,
Thanks for your quick response. The flat parts of the plot are data gaps. Would that matter for the use of interp1? Do not suppose, since it hasn't been an issue previous?
Thanks.
Rgrds,
Stephen23
Stephen23 2019 年 4 月 12 日
@Wessel ter Laare: please upload your data in one .mat file by clicking the paperclip button.
Wessel ter Laare
Wessel ter Laare 2019 年 4 月 12 日
Hi Stephen, Attached. Thanks!
Adam
Adam 2019 年 4 月 12 日
numel( unique( DateBuoy ) )
gives an answer 2 fewer than the total number of points in DateBuoy so 2 of the values in there somewhere are non-unique.
Wessel ter Laare
Wessel ter Laare 2019 年 4 月 12 日
Yep. That dit the trick! Thanks a lot.

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

回答 (0 件)

タグ

質問済み:

2019 年 4 月 12 日

コメント済み:

2019 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by