Interpolation of non monotonic data.

13 visualizaciones (últimos 30 días)
TEJASHKUMAR PATEL
TEJASHKUMAR PATEL el 8 de Dic. de 2020
Comentada: TEJASHKUMAR PATEL el 9 de Dic. de 2020
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')
  3 comentarios
TEJASHKUMAR PATEL
TEJASHKUMAR PATEL el 8 de Dic. de 2020
Error in interp1 (line 161)
F = griddedInterpolant(X,V,method);
Error in CO2interpolation (line 16)
u=interp1(fCO2,timeCO2/1000,280);
TEJASHKUMAR PATEL
TEJASHKUMAR PATEL el 8 de Dic. de 2020
Is there any way or any function I can interpolate CO2 and temperature with respect to time? Any command or function syntax?

Iniciar sesión para comentar.

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 8 de Dic. de 2020
Editada: Bjorn Gustavsson el 9 de Dic. de 2020
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
  8 comentarios
Bjorn Gustavsson
Bjorn Gustavsson el 9 de Dic. de 2020
If you do:
timeCO2=1950-ageCO2;
subplot(2,2,1),plot(diff(timeT),'.')
subplot(2,2,2),plot(diff(timeT)==0,'.')
subplot(2,2,4),plot(diff(timeCO2)==0,'.')
subplot(2,2,3),plot(diff(timeCO2),'.')
You will see that two consecutive points in your CO2-data are from the same time. That has to be resolved somehow. This way you get the average CO2-value:
timeCO2=1950-ageCO2;
idtCO2 = find(diff(timeCO2)==0);
timeCO2(idtCO2) = timeCO2(idtCO2)/2 + timeCO2(idtCO2+1)/2; % Average
timeCO2(idtCO2+1) = []; % remove the second point from the data
fCO2=CO2data.fCO2; % Same procedure for fCO2:
fCO2(idtCO2) = fCO2(idtCO2)/2 + fCO2(idtCO2+1)/2; % Average
fCO2(idtCO2+1) = []; % Remove second point
That is then possible to re-interpolate, here to 100000-timesteps between the first and last time in either data-set:
fCO2_reinterpolated = interp1(timeCO2,fCO2,linspace(min(min(timeCO2),min(timeT)),max(max(timeCO2),max(timeT)),1e5),'pchip');
HTH
TEJASHKUMAR PATEL
TEJASHKUMAR PATEL el 9 de Dic. de 2020
Hey, above solution almost solved all of my problem regarding interpolation of non monotonic incresing data. Thank you very much. Now I will look into this little bit more in deep...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by