help-octave
[Top][All Lists]
Advanced

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

Re: Vectorisation


From: Andy Buckle
Subject: Re: Vectorisation
Date: Wed, 7 Jul 2010 17:33:58 +0100

2010/7/7 Jordi Gutiérrez Hermoso <address@hidden>:
> 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.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>

I think this example will yield a cumulative histogram, I think Gaston
wanted a differential histogram.

-- 
/* andy buckle */



reply via email to

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