Interp1 grid vectors must contain unique points

I have a time series of daily temperature and rainfall data from 1880 to 2018, which I am trying to interpolate. It returns the error 'grid vectors must contain unique points', and I used the unique function before, which basically removed over 50,000 data points from each dataset. Is there any way to remove the duplicate values without changing my entire dataset? I inserted the code for my interpolation in case this is the problem. All the date values are Matlab datenumbers.
% Linear
sheffDailyMaxTemp_interp_linear = interp1(sheffTempMatlabDate, sheffDailyMaxTemp, min(sheffTempMatlabDate):max(sheffTempMatlabDate),'linear','extrap');
sheffDailyMinTemp_interp_linear = interp1(sheffTempMatlabDate, sheffDailyMinTemp, min(sheffTempMatlabDate):max(sheffTempMatlabDate),'linear','extrap');
sheffDailyRain_interp_linear = interp1(sheffRainMatlabDate, sheffDailyRain, min(sheffRainMatlabDate):max(sheffRainMatlabDate),'linear','extrap');
% pchip
sheffDailyMaxTemp_interp_pchip = interp1(sheffTempMatlabDate, sheffDailyMaxTemp, min(sheffTempMatlabDate):max(sheffTempMatlabDate),'pchip','extrap');
sheffDailyMinTemp_interp_pchip = interp1(sheffTempMatlabDate, sheffDailyMinTemp, min(sheffTempMatlabDate):max(sheffTempMatlabDate),'pchip','extrap');
sheffDailyRain_interp_pchip = interp1(sheffRainMatlabDate, sheffDailyRain, min(sheffRainMatlabDate):max(sheffRainMatlabDate),'pchip','extrap');
% spline
sheffDailyMaxTemp_interp_spline = interp1(sheffTempMatlabDate, sheffDailyMaxTemp, min(sheffTempMatlabDate):max(sheffTempMatlabDate),'spline','extrap');
sheffDailyMinTemp_interp_spline = interp1(sheffTempMatlabDate, sheffDailyMinTemp, min(sheffTempMatlabDate):max(sheffTempMatlabDate),'spline','extrap');
sheffDailyRain_interp_spline = interp1(sheffRainMatlabDate, sheffDailyRain, min(sheffRainMatlabDate):max(sheffRainMatlabDate),'spline','extrap');

4 Comments

Adam
Adam on 21 May 2018
Edited: Adam on 21 May 2018
What is the result you are expecting? You want to remove duplicates, but not change the results??! You don't have to change the originals, but if you remove duplicates of course the data will change, whether it is a copy or the original
I want to remove the duplicates that are stopping the interpolation from working, without losing the entirety of my dataset. I know the data will change, but surely not nearly all of my points?
It depends if you are using unique correctly I guess.
What is the data type of sheffTempMatlabDate ? What are some example values from it? How many unique values are you expecting for it? Is it possible that your time series covers multiple locations so you have multiple data points for each day, one for each location?

Sign in to comment.

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 21 May 2018

Commented:

on 21 May 2018

Community Treasure Hunt

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

Start Hunting!