From: Steve Amphlett on
Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <485e09eb-631f-4835-b91c-07549fea431d(a)u26g2000yqu.googlegroups.com>...
> On Jul 22, 9:24 am, "Steve Amphlett" <Firstname.Lastn...(a)Where-I-
> Work.com> wrote:
> > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <be8c1193-d5a2-445f-8c88-022481175...(a)e5g2000yqn.googlegroups.com>...
> >
> > > There must be a "filter" way of doing "backfill" fast?
> >
> > A MEX would be trivial.  Here is a more traditional ML approach.  It doesn't do the ends properly though, this is left as an exercise for the OP.
> >
> > x=[1;1;2;1;2;3;NaN;NaN;3;2;NaN;NaN;NaN;4;1;5;2;NaN;3];
> >
> > y=zeros(size(x));
> > idx=isnan(x);
> >
> > idx1=find(diff(idx)>0);
> > idx2=find(diff(idx)<0);
> >
> > y(idx1+1)=x(idx1);
> > y(idx2+1)=-x(idx1);
> > y=cumsum(y);
> > y(~idx)=x(~idx);
> >
> > [x z]
>
> very cool.
>
> but doesn't work on:
>
> x=[NaN; NaN; 1;1;2;1;2;3;NaN;NaN;3;2;NaN;NaN;NaN;4;1;5;2;NaN;3];
>
> please note I added the initial 2 "NaN"s to test your program,
>
> it broke
>
> the initial two "NaN"s need to remain there because there is no way to
> backfill these initial "NaN"s...

Hence my closing statement:

"It doesn't do the ends properly though, this is left as an exercise for the OP."
From: Luna Moon on
On Jul 22, 4:33 pm, "Doug Weathers" <douglas.e.weath...(a)nasa.gov>
wrote:
> Luna Moon <lunamoonm...(a)gmail.com> wrote in message <485e09eb-631f-4835-b91c-07549fea4...(a)u26g2000yqu.googlegroups.com>...
> > the initial two "NaN"s need to remain there because there is no way to
> > backfill these initial "NaN"s...
>
> Could you lop them off, run the given routine, then put them back?
>
>

Of course I knew that, but how to do that "cut off", and "put back"
parts fast?

Thanks
From: Luna Moon on
On Jul 22, 6:01 pm, Luna Moon <lunamoonm...(a)gmail.com> wrote:
> On Jul 22, 4:33 pm, "Doug Weathers" <douglas.e.weath...(a)nasa.gov>
> wrote:
>
> > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <485e09eb-631f-4835-b91c-07549fea4...(a)u26g2000yqu.googlegroups.com>...
> > > the initial two "NaN"s need to remain there because there is no way to
> > > backfill these initial "NaN"s...
>
> > Could you lop them off, run the given routine, then put them back?
>
> Of course I knew that, but how to do that "cut off", and "put back"
> parts fast?
>
> Thanks

Okay, there are better solutions,

we can wrap the series by one number at the beginning and one number
at the end.
From: dpb on
Luna Moon wrote:
> On Jul 22, 6:01 pm, Luna Moon <lunamoonm...(a)gmail.com> wrote:
>> On Jul 22, 4:33 pm, "Doug Weathers" <douglas.e.weath...(a)nasa.gov>
>> wrote:
>>
>>> Luna Moon <lunamoonm...(a)gmail.com> wrote in message <485e09eb-631f-4835-b91c-07549fea4...(a)u26g2000yqu.googlegroups.com>...
>>>> the initial two "NaN"s need to remain there because there is no way to
>>>> backfill these initial "NaN"s...
>>> Could you lop them off, run the given routine, then put them back?
>> Of course I knew that, but how to do that "cut off", and "put back"
>> parts fast?
>>
>> Thanks
>
> Okay, there are better solutions,
>
> we can wrap the series by one number at the beginning and one number
> at the end.

Finding the actual series to operate on isn't much or any harder...

>> x=[1;1;2;1;2;3;NaN;NaN;3;2;NaN;NaN;NaN;4;1;5;2;NaN;3];
>> z=[nan;nan;x];
>> idx=max(1,min(find(~isnan(z))));
>> all(isnan(z(idx:end))==isnan(x))
ans =
1

Here z is Steve's example x vector w/ a couple of NaN prepended.

Operate on z(idx:end) instead of x.

--
From: Luna Moon on
On Jul 22, 8:45 pm, dpb <n...(a)non.net> wrote:
> Luna Moon wrote:
> > On Jul 22, 6:01 pm, Luna Moon <lunamoonm...(a)gmail.com> wrote:
> >> On Jul 22, 4:33 pm, "Doug Weathers" <douglas.e.weath...(a)nasa.gov>
> >> wrote:
>
> >>> Luna Moon <lunamoonm...(a)gmail.com> wrote in message <485e09eb-631f-4835-b91c-07549fea4...(a)u26g2000yqu.googlegroups.com>...
> >>>> the initial two "NaN"s need to remain there because there is no way to
> >>>> backfill these initial "NaN"s...
> >>> Could you lop them off, run the given routine, then put them back?
> >> Of course I knew that, but how to do that "cut off", and "put back"
> >> parts fast?
>
> >> Thanks
>
> > Okay, there are better solutions,
>
> > we can wrap the series by one number at the beginning and one number
> > at the end.
>
> Finding the actual series to operate on isn't much or any harder...
>
>  >> x=[1;1;2;1;2;3;NaN;NaN;3;2;NaN;NaN;NaN;4;1;5;2;NaN;3];
>  >> z=[nan;nan;x];
>  >> idx=max(1,min(find(~isnan(z))));
>  >> all(isnan(z(idx:end))==isnan(x))
> ans =
>       1
>
> Here z is Steve's example x vector w/ a couple of NaN prepended.
>
> Operate on z(idx:end) instead of x.
>
> --- Hide quoted text -
>
> - Show quoted text -

I think your "ismember" is used wrongly...
it has a bug...