Borrar filtros
Borrar filtros

A question regarding one of my previous questions

1 visualización (últimos 30 días)
salva
salva el 14 de Ag. de 2012
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 comentario
salva
salva el 15 de Ag. de 2012
Will I be correct if i use (1:n)' instead of (1:n-1)'
thanks again

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Ag. de 2012
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 comentarios
salva
salva el 15 de Ag. de 2012
I think that Y has the same length as x. In bith cases the size is 12 by 1
Walter Roberson
Walter Roberson el 15 de Ag. de 2012
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by