Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: interpolate missing data
Date: Tue, 6 May 2008 18:58:03 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 66
Message-ID: <fvq9nr$amm$1@fred.mathworks.com>
References: <fvq09u$59o$1@fred.mathworks.com> <fvq12t$n6i$1@fred.mathworks.com> <fvq8k7$4h2$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210100283 10966 172.30.248.35 (6 May 2008 18:58:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 6 May 2008 18:58:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:466986



"Hydroman S" <amirgsalem@gmail.com> wrote in message 
<fvq8k7$4h2$1@fred.mathworks.com>...
> Thanks John,
> 
> Here is what I did, and it seems to have worked, I just 
> wanted to get your blessing.  Also, I was not sure how to 
> implement a &#8216;spline&#8217; interpolation using your 
> inpaint_nans.m function. 
> 
> 
> 
> 
> a = magic(4); a(2,2) = NaN ; a(3,3)=NaN
> [M,N] = size(a);
>     for k = 1:length(M)
> a=inpaint_nans(a)
>     end
> 
> a =
> 
>     16     2     3    13
>      5   NaN    10     8
>      9     7   NaN    12
>      4    14    15     1
> 
> 
> a =
> 
>    16.0000    2.0000    3.0000   13.0000
>     5.0000    6.0000   10.0000    8.0000
>     9.0000    7.0000   11.0000   12.0000
>     4.0000   14.0000   15.0000    1.0000

What you did was equivalent to a single call
to inpaint_nans, working in 2 dimensions.
Note the difference below between b and c.

a = magic(4); a(2,2) = NaN ; a(3,3)=NaN
b=inpaint_nans(a)

[M,N] = size(a);
c = a;
for i = 1:M
  c(:,i) = inpaint_nans(a(:,i));
end
c


b =
           16            2            3           13
            5            6           10            8
            9            7           11           12
            4           14           15            1

c =
           16            2            3           13
            5          3.6           10            8
            9            7         13.4           12
            4           14           15            1

Of course, you need to decide whether
one is more appropriate than the other.
It depends on how the columns of a are
related to each other.

John