필터 지우기
필터 지우기

A question regarding one of my previous questions

조회 수: 1 (최근 30일)
salva
salva 2012년 8월 14일
Dear all,
In my previous question
I had
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' NaN 148.2583
1 '1-2 2005' NaN 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 NaN
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' NaN 148.2583
2 '1-2 2005' NaN 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 NaN
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' NaN 148.2583
3 '1-2 2005' NaN 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 NaN
3 '11-12 2005' 0.2938 2.854}
These are bimonthly data and I wanted to obtain estimated monthly averages The solution that was given was
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
The only thing that I do not understand is why (1:n-1)' and not (1:n)'
thanks
  댓글 수: 1
salva
salva 2012년 8월 15일
Will I be correct if i use (1:n)' instead of (1:n-1)'
thanks again

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 15일
The code is wrong, for the same reason that I pointed out in one of your previous Questions.
If Y is a vector, it must have the same length as x
Your Y is not the same length as your x.
Whether you use (1:n-1) or (1:n) is not going to matter as the call is going to error out anyhow.
  댓글 수: 2
salva
salva 2012년 8월 15일
I think that Y has the same length as x. In bith cases the size is 12 by 1
Walter Roberson
Walter Roberson 2012년 8월 15일
In that csse, n-1 is correct. 1:2:n with n being even, ends at n-1 not at n. 1, 3, 5, 7... never even, so there is no input past 23 that would allow you to interpolate point 24 without using extrapolation.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by