interpolation for irregural observations
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2012 年 8 月 10 日
Looks to me like you deleted your old (identical) question and reposted it. :-(
回答 (1 件)
Sean de Wolski
2012 年 8 月 10 日
Convert the dates to date numbers ( doc datenum ) and then use them as the x values corresponding to your data.
2 件のコメント
Sean de Wolski
2012 年 8 月 10 日
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.
参考
カテゴリ
Help Center および File Exchange で Interpolating Gridded Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!