replace missing value in a matrix using intropolated values
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Andrei Bobrov
2013년 1월 16일
편집: Andrei Bobrov
2013년 1월 16일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!