|
On May 7, 9:44=A0am, "Hydroman S" <amirgsa...@gmail.com> wrote:
> % the example
>
> a =3D magic(4); a(2,2) =3D NaN ; a(3,3)=3DNaN
> b=3Dinpaint_nans(a)
> [M,N] =3D size(a);
> c =3D a;
> for i =3D 1:M
> =A0 c(:,i) =3D inpaint_nans(a(:,i));
> end
> c
>
> if I paste above example in matlab 7.0.0.19920 (R14), this
> is the output I get:
>
> a =3D
>
> =A0 =A0 16 =A0 =A0 2 =A0 =A0 3 =A0 =A013
> =A0 =A0 =A05 =A0 NaN =A0 =A010 =A0 =A0 8
> =A0 =A0 =A09 =A0 =A0 7 =A0 NaN =A0 =A012
> =A0 =A0 =A04 =A0 =A014 =A0 =A015 =A0 =A0 1
>
> b =3D
>
> =A0 =A0 =A0 =A0 =A0 =A016 =A0 =A0 =A0 =A0 =A0 =A02 =A0 =A0 =A0 =A0 =A0 =A0=
3 =A0 =A0 =A0 =A0 =A0 13
> =A0 =A0 =A0 =A0 =A0 =A0 5 =A0 =A0 =A0 =A0 =A0 =A06 =A0 =A0 =A0 =A0 =A0 10 =
=A0 =A0 =A0 =A0 =A0 =A08
> =A0 =A0 =A0 =A0 =A0 =A0 9 =A0 =A0 =A0 =A0 =A0 =A07 =A0 =A0 =A0 =A0 =A0 11 =
=A0 =A0 =A0 =A0 =A0 12
> =A0 =A0 =A0 =A0 =A0 =A0 4 =A0 =A0 =A0 =A0 =A0 14 =A0 =A0 =A0 =A0 =A0 15 =
=A0 =A0 =A0 =A0 =A0 =A01
>
> Warning: Matrix is singular to working precision.> In inpaint_nans at 170
>
> Warning: Matrix is singular to working precision.
>
> > In inpaint_nans at 170
>
> c =3D
>
> =A0 =A0 =A0 =A0 =A0 =A016 =A0 =A0 =A0 =A0 =A0 =A02 =A0 =A0 =A0 =A0 =A0 =A0=
3 =A0 =A0 =A0 =A0 =A0 13
> =A0 =A0 =A0 =A0 =A0 =A0 5 =A0 =A0 =A0 =A0 =A03.6 =A0 =A0 =A0 =A0 =A0 10 =
=A0 =A0 =A0 =A0 =A0 =A08
> =A0 =A0 =A0 =A0 =A0 =A0 9 =A0 =A0 =A0 =A0 =A0 =A07 =A0 =A0 =A0 =A0 13.4 =
=A0 =A0 =A0 =A0 =A0 12
> =A0 =A0 =A0 =A0 =A0 =A0 4 =A0 =A0 =A0 =A0 =A0 14 =A0 =A0 =A0 =A0 =A0 15 =
=A0 =A0 =A0 =A0 =A0 =A01
>
> and if I paste it in matlab 6.1.0.450 (R12.1), this is
> what I get:
>
> a =3D
>
> =A0 =A0 16 =A0 =A0 2 =A0 =A0 3 =A0 =A013
> =A0 =A0 =A05 =A0 NaN =A0 =A010 =A0 =A0 8
> =A0 =A0 =A09 =A0 =A0 7 =A0 NaN =A0 =A012
> =A0 =A0 =A04 =A0 =A014 =A0 =A015 =A0 =A0 1
>
> ??? Error: File: C:\MATLAB6p1\work\inpaint_nans.m Line:
> 123 Column: 16
> Expected a variable, function, or constant, found "|".
Here is an alternative routine that is much simpler than
inpaint_nans. It works on vectors and simply does linear
interpolation across gaps. It comes from Rich Pawlowicz's t_tide
package:
function y=3Dfixgaps(x);
% FIXGAPS Linearly interpolates gaps in a time series
% YOUT=3DFIXGAPS(YIN) linearly interpolates over NaN
% in the input time series (may be complex), but ignores
% trailing and leading NaN.
%
% R. Pawlowicz 6/Nov/99
y=3Dx;
bd=3Disnan(x);
gd=3Dfind(~bd);
bd([1:(min(gd)-1) (max(gd)+1):end])=3D0;
y(bd)=3Dinterp1(gd,x(gd),find(bd));
|