The fastest is probably to write a PP routine that does it, but it is 
easily done using cc8compt (yes, I know it is supposed to be for images, 
but it works here too :):

   $a = pdl([0,0,1,1,1,0,0,0,0,1,1,1,1,0,0])
   $levels = cc8compt($a)
   $n_levels = max($levels)
   $i_level = which($levels == 1)
   $beg=$i_level((0))
   $end = $i_level((-1))

for instance. You can of course then return all the begin & end levels 
quite easily with a loop:

   sub splitit {
    my $a = shift;
    $levels = cc8compt($a);
    $n_levels = max($levels);
    my @beg=();
    my @end=();
    for (my $i=1; $i<=$n_levels; $i++) {
        $i_level = which($levels == $i);
        push @beg, $i_level((0));
        push @end, $i_level((-1));
     }
     return (pdl(@beg), pdl(@end));
  }

Which then gives:

perldl> ($beg, $end) = splitit($a)

perldl> p $beg
[2 9]
perldl> p $end
[4 12]


Hope this helps!

                Cheers,
                        Jarle.



Martin A. Hansen wrote:
> Hello,
> 
> 
> I have a 1D piddle [0,0,1,1,1,0,0,0,0,1,1,1,1,0,0]
> 
> and would like to scan the piddle for the next interval of non-zero 
> values given an offset:
> 
> ( beg, end ) = scan( pdl, 0 ); # return beg=2, end=4
> ( beg, end ) = scan( pdl, 5 ); # return beg=9, end=12
> 
> 
> How do you do that with PDL ?
> 
> 
> 
> Martin
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl


_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to