help-octave
[Top][All Lists]
Advanced

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

Re: Vectorisation


From: Jordi Gutiérrez Hermoso
Subject: Re: Vectorisation
Date: Wed, 7 Jul 2010 10:48:50 -0500

On 7 July 2010 10:21, gastonjulia <address@hidden> wrote:

> octave1:>count = zeros(1,20);
> octave2:>for i = 1:length(data)
> octave3:>    count(data(i, 3))++;
> octave4:>endfor

Ooh, I love vectorisation puzzles. Here's my solution. I wasn't able
to get rid of for loops, but only replaced it by a much shorter one.
It's actually the same solution if you do [count, rubbish] =
hist(data,20);

     octave:1> count = zeros(20,1);
     octave:2> data = ceil(rand(2e6,1)*20);
     octave:3> tic, for i =1:20; count(i) = sum(data<=i); endfor, toc

HTH,
- Jordi G. H.



reply via email to

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