필터 지우기
필터 지우기

interpolation for irregural observations

조회 수: 1 (최근 30일)
salva
salva 2012년 8월 10일
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
Walter Roberson 2012년 8월 10일
Looks to me like you deleted your old (identical) question and reposted it. :-(
salva
salva 2012년 8월 10일
편집: salva 2012년 8월 10일
correct!:)
Matlab is great and all of you as well!

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
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
salva
salva 2012년 8월 10일
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 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 CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by