interpolation for irregural observations

1 visualizzazione (ultimi 30 giorni)
salva
salva il 10 Ago 2012
Dear all,
I have
A = {
1 '1-2 2004' 0.256 0.385
1 '3-4 2004' 0.268 3.0394
1 '5-6 2004' 0.0504 0.6475
1 '7-8 2004' 14.0985 148.2583
1 '9-10 2004' 0.1128 1.1506
1 '11-12 2004' 0.322 148.2583
1 '1-2 2005' 0.322 148.2583
1 '3-4 2005' 2.5852 34.0146
1 '5-6 2005' 0.322 3.2846
1 '7-8 2005' 14.0985 148.2583
1 '9-10 2005' 2.5852 0.322
1 '11-12 2005' 0.2938 2.854
2 '1-2 2004' 0.256 0.385
2 '3-4 2004' 0.268 3.0394
2 '5-6 2004' 0.0504 0.6475
2 '7-8 2004' 14.0985 148.2583
2 '9-10 2004' 0.1128 1.1506
2 '11-12 2004' 0.322 148.2583
2 '1-2 2005' 0.322 148.2583
2 '3-4 2005' 2.5852 34.0146
2 '5-6 2005' 0.322 3.2846
2 '7-8 2005' 14.0985 148.2583
2 '9-10 2005' 2.5852 0.322
2 '11-12 2005' 0.2938 2.854
3 '1-2 2004' 0.256 0.385
3 '3-4 2004' 0.268 3.0394
3 '5-6 2004' 0.0504 0.6475
3 '7-8 2004' 14.0985 148.2583
3 '9-10 2004' 0.1128 1.1506
3 '11-12 2004' 0.322 148.2583
3 '1-2 2005' 0.322 148.2583
3 '3-4 2005' 2.5852 34.0146
3 '5-6 2005' 0.322 3.2846
3 '7-8 2005' 14.0985 148.2583
3 '9-10 2005' 2.5852 0.322
3 '11-12 2005' 0.2938 2.854}These data are bimonthly data.
The code
data = inpaint_nans(cell2mat(A(:,3:4)),2);
% Partition interpolation in blocks (first column)
blocks = [A{:,1}];
unBlocks = unique(blocks);
% Preallocate
interpData = cell(numel(unBlocks),1);
% Interpolate each block
for b = unBlocks
idxBlock = b == blocks; % index the block
n = nnz(idxBlock)*2; % counts its length
interpData{b} = interp1((1:2:n)', data(idxBlock,:),(1:n-1)');
end
transforms these bimonthly data to monthly.
The only problem is that with this approach assumes that every month has same length.
Is it possible to modify it so as to take into account that the months have different length?
thanks
  2 Commenti
Walter Roberson
Walter Roberson il 10 Ago 2012
Looks to me like you deleted your old (identical) question and reposted it. :-(
salva
salva il 10 Ago 2012
Modificato: salva il 10 Ago 2012
correct!:)
Matlab is great and all of you as well!

Accedi per commentare.

Risposte (1)

Sean de Wolski
Sean de Wolski il 10 Ago 2012
Convert the dates to date numbers ( doc datenum ) and then use them as the x values corresponding to your data.
  2 Commenti
salva
salva il 10 Ago 2012
Hi Sean. I am a bit confused. You mean to convert the months to numbers using datemun. For instance
datenum('09/2001', 'mm/yyyy')=x and then
outqq = interp1(x,A(x,:),x);
Am I right?
cheers
Sean de Wolski
Sean de Wolski il 10 Ago 2012
Yes. The date numbers will be a numerical representation of the days. So March 17th will be 12 different from March 29th which will be two different from March 31st. Then when you use interp1 the non-even spacing will be accounted for.

Accedi per commentare.

Categorie

Scopri di più su Interpolating Gridded Data in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by