MATLAB: Interpolation of non monotonic data.

cross correlationinterpolationmatlab function

Hello, I need to interpolate two data. One is temperature and other is CO2. I need to interpolate it on same time interval and want to see the value of both (whose value is higher than other). I have tried interp1 function and I have been through many questions and answers here but couldn't find related. I have attached my code here. I always got the error of non monotonic increasing. I have a data from last thousand of years till 2010. In that temperature and CO2 has increased and decreased in some intervals and I can't reshape as it affects on final result. If anyone can help I would say please. I
clear all
load CO2data % Historical CO2 data from Harris
ageCO2=CO2data.years;
fCO2=CO2data.fCO2;
timeCO2=1950-ageCO2;
size(timeCO2)
figure(101)
plot(timeCO2/1000,fCO2)
xlabel('time (1000 years)')
ylabel('CO2 level (ppm)')
title('Historical CO2 level in the atmosphere (ppm)')
load Tdata % Historical temp data from Harris
ageT=Tdata.years;
Temp=Tdata.T;
timeT=1950-ageT;
size(timeT)
figure(102)
plot(timeT/1000,Temp)
xlabel('time (1000 years)')
ylabel('Temperature anomaly (C)')
title('Historical temperature anomaly (C)')
figure(103)
T=plotyy(timeCO2/1000,fCO2,timeT/1000,Temp);
xlabel('time ( 1000 years)')
ylabel(T(1),'CO2 level (ppm)')
ylabel(T(2),'historic temperature level(c)')
title('Atmospheric CO2 vs Temperature level')
u=interp1(fCO2,timeCO2/1000,280);
new_fCO2=linspace(280,191,length(fCO2));
new_timeCO2=interp1(fCO2,timeCO2/1000,new_fCO2,'spline');
figure(102)
plot(fCO2,timeCO2/1000,new_fCO2,new_timeCO2,'-o')

Best Answer

The interpolation-function does something else than what you seem to try. It takes one data-vector, D, taken at a discrete set of monotously (sp?) varying points, t, and calculates interpolatevalues of D at another set of points, ti. In your case you have your t as years, if I understand correctly, and some corresponding measure of CO2. you might reinterpolate that data to a regular "montly" value like this:
ti = linspace(min(timeCO2),max(timeCO2),12*round(max(timeCO2)-min(timeCO2)));
fCO2_new = interp1(timeCO2,fCO2,ti,'pchip');
That is how the interpolation-function works. If that is the operation you need is not clear from the code you posted.
HTH
Related Question