help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zero or not?


From: Przemek Klosowski
Subject: Re: Zero or not?
Date: Tue, 24 Jul 2007 10:47:06 -0400 (EDT)

   I'm new to "octave".  I'm translating from a method I use in "pascal"

   Avg = sum(abs(X))/(size(X)(2));     # Figure a dividing line

Or you could just say Avg=mean(X);

   Gate = Avg < abs(X);                      # Classify X

   Total = sum(X .* Gate) + sum(X .* !Gate);

Or, simpler,  avg=mean(x); sum(x(x>=avg)) + sum(x(x<avg))

I must say that this method is surprisingly good: twice as fast
as the full sort, while getting most of the accuracy:

x=exp(100*rand(1,1000000));

tic; avg=mean(x); sum(x(x>=avg)) + sum(x(x<avg))-sum(x), toc
  ans =  7.3219e+34
                     Elapsed time is 0.308838 seconds.
tic; sum(sort(x))-sum(x), toc
  ans =  7.0664e+34
                     Elapsed time is 0.689682 seconds.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]