replace missing value in a matrix using intropolated values
Afficher commentaires plus anciens
Dear All,
I have a matrix A as below: A =
1.1093 -0.7697 1.1006 -0.6156 0.4882 -0.8045 0.1049
NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN
-1.2141 1.1174 -1.4916 0.8886 1.4193 -0.2437 -0.6669
-1.1135 -1.0891 -0.7423 -0.7648 0.2916 0.2157 0.1873
-0.0068 NaN -1.0616 -1.4023 0.1978 -1.1658 -0.0825
1.5326 0.5525 NaN -1.4224 1.5877 -1.1480 NaN
I want to replace the NaN with the values generated from interpolation which can take care of both the interpolation for rows and column. So far I have in mind is take interpolation for row get value a_row; then do it for column get a_column. In the end replace nan with the mean value for the two. Can anyone help me about this? Also, I have problems with specifying y for the function : output(a)= interp1(A,y,'linear');
if I don't know y how should I specify here?
thanks a lot in advance
Réponses (1)
Andrei Bobrov
le 16 Jan 2013
Modifié(e) : Andrei Bobrov
le 16 Jan 2013
one way
t = ~isnan(A);
[x,y] = find(t);
F = TriScatteredInterp(x,y,A(t));
[ii,jj] = ndgrid(1:size(A,1),1:size(A,2));
out = F(ii,jj);
ADD variant
out(end) = mean(cellfun(@(x)interp1(1:2,x(1:2),3,'linear','extrap'),...
{out(end,end-[2 1 0])', out(end-[2 1 0],end),...
out(end - (size(out,1)+1)*(2:-1:0))'}));
2 commentaires
Skirt Zhang
le 16 Jan 2013
Andrei Bobrov
le 16 Jan 2013
Hi Skirt! See ADD part in my answer.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!