Calculating the variance of differences between linear interpolant of monthly means and raw data

1 view (last 30 days)
Hi, A bit of background; this is the SOCAT database which has an accompanying MATLAB reader file. The file produces a vector of CO2 raw data "xCO2water_equ_dry" and associated month, day and year vectors "mon", "day, "yr" so that each xCO2 value has a timestamp.
I have used this code to find the monthly mean of measured CO2 content of a 1x1 latitude-longitude grid in the tropical pacific.
  • for i=12
  • tmp1=find(latitude>=i & latitude<i+1);
  • lat_tmp=latitude(tmp1);
  • long_tmp=longitude(tmp1);
  • mon_tmp=mon(tmp1);
  • fCO2rec_tmp=xCO2water_equ_dry(tmp1);
  • for j=144
  • tmp2=find(long_tmp>=j & long_tmp<=j+1);
  • lat_tmp2=lat_tmp(tmp2);
  • long_tmp2=long_tmp(tmp2);
  • mon_tmp2=mon_tmp(tmp2);
  • fCO2rec_tmp2=fCO2rec_tmp(tmp2);
  • if isempty(fCO2rec_tmp)
  • else
  • for k=1:12
  • idx2=find(mon_tmp2==k);
  • month_mean(k)=nanmean(fCO2rec_tmp2(idx2)); %#ok<SAGROW>
  • end
  • end
  • end
  • end
I then used this code to perform a linear interpolation of the monthly means:
month_mean_new=[month_mean(12), month_mean, month_mean(1)]
x=-0.5:1:12.5
xq=0:1:12
vq=interp1(x,v,xq)
The idea was to calculate a linear interpolation such that it "wrapped around" to the mean of January in the new year in month "13," and to make the monthly means occur at the middle of each month.
The more complicated coding that I have very little idea how to accomplish even after some web-sleuthing and looking at the interp1 page is this: I wish to take the raw CO2 data from "xCO2water_equ_dry" and calculate the difference between CO2 raw data and linear interpolant by date (approximately). So, for instance if there was an xCO2 data point of 387.2 on January 31st, I want to calculate the difference between 387.2 and the linear interpolant halfway between the monthly mean for January and February. I was hoping I could calulate the difference between linear interpolant and all raw data at their time points, collect it in a vector, and then calculate the variance of that data.
The overall goal is to calculate to what degree pH fluctuates according to a seasonal trend, I hope to divide the variance of the linear interpolant by the sum of the variance of the linear interpolant and the variance of the differences between the raw data and the interpolant.
I hope this is clear. Thank you so much, Moey Rojas

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!