In your $idx below, you don't want the second occurrence of 0 in $b, you want 
the first occurrence of 0 in $a.  Because if your data for some reason has no 0 
in it, then your method fails.  All those zeroes in $rv are to be expected--the 
$a and $b arrays have the same size as your input data, so you have to 
truncate.  Re-read the rle() docs.

For finding how many numbers fall in a given range, hist() is your friend if 
the ranges are consecutive and evenly spaced.

pdl> ??sort 

will give you a list of all the sorting routines.  It sounds like you want 
qsortvec().


On Feb 10, 2014, at 9:20 PM, mraptor wrote:

> How do I sort multicolumns matrix by single columns...
> -------| http://ifni.co
> 
> 
> On Mon, Feb 10, 2014 at 10:24 PM, mraptor <[email protected]> wrote:
>> this worked out :
>> sub freq {
>>   my $data = shift;
>>   my ($a,$b) = rle qsort $data;
>>   #find the idx of the second zero
>>   my $idx = which($b == 0)->(1);#2nd elem
>>   my $rv = pdl $b(1:$idx-1), $a(1:$idx-1);
>>   return $rv
>> }
>> -------| http://ifni.co
>> 
>> 
>> On Mon, Feb 10, 2014 at 10:06 PM, mraptor <[email protected]> wrote:
>>> thanks..this seem to do it :
>>> 
>>>  ($a,$b) = rle qsort $data;
>>>  $rv = pdl $a, $b;
>>> 
>>> the only thing which is no big deal is that it seems to if I process
>>> 100 elements and I get let say 5 elem only after i remove the
>>> repetitions it still returns 100 elements instead 5..
>>> 
>>> pdl> p $rv->transpose
>>> 
>>> [
>>> [-5  1]
>>> [-3  3]
>>> [-2  7]
>>> [-1 17]
>>> [ 0 46]
>>> [ 1 17]
>>> [ 2  3]
>>> [ 3  1]
>>> [ 4  2]
>>> [ 5  1]
>>> [ 6  1]
>>> [10  1]
>>> [ 0  0]
>>> [ 0  0]
>>> 
>>> ...... alot of zeros after this ... :)
>>> 
>>> -------| http://ifni.co
>>> 
>>> 
>>> On Mon, Feb 10, 2014 at 9:34 PM, Craig DeForest
>>> <[email protected]> wrote:
>>>> Check out rle() -- it is in the standard PDL releases!
>>>> 
>>>> (Mobile)
>>>> 
>>>> 
>>>>> On Feb 10, 2014, at 7:09 PM, mraptor <[email protected]> wrote:
>>>>> 
>>>>> Do you guys, know a way to count repeated numbers. f.e. let say I have
>>>>> this pdl :
>>>>> 
>>>>> [-1 0 0 0 0 0 0 0 0 -1 0 1 1 -2 10 -2 1 2 0 0 0 1 1 -1 0 1 0 0 0 0 0
>>>>> -2 0 0 -1 0 1 -1 -1 -2 -1 -1 0 0 1 -1 -1 0 0 0 1 0 0 1 -1 -1 1 1 -3 -1
>>>>> 0 2 0 6 3 4 5 0 -1 0 -1 -3 -2 0 1 0 1 0 0 4 -3 -5 -2 2 -1 0 1 0 -2 1 1
>>>>> 0 0 0 0 0 0 0 0 -1]
>>>>> 
>>>>> how would I create a pdl than contains the number and how many times
>>>>> the number occurred ?
>>>>> What about if I wanted to count numbers in a range...let say the pdl
>>>>> had numbers between 1 and 100 and I wanted to count the numbers
>>>>> between 1-10, 11-20, 21-30,...
>>>>> 
>>>>> thanks
>>>>> 
>>>>> 
>>>>> -------| http://ifni.co
>>>>> 
>>>>> _______________________________________________
>>>>> 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
> 


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

Reply via email to