help-octave
[Top][All Lists]
Advanced

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

Vectorisation


From: gastonjulia
Subject: Vectorisation
Date: Wed, 7 Jul 2010 08:21:44 -0700 (PDT)

Hi there,

I always knew it would come to point where my for loops are taking toooooo
long. I know that I should use vectorised code, I do.
But I can't figure out how I would vectorise this task:
- I am having a 5 times 2,000,000 matrix (approximately)
- Column 3 contains integer numbers between 1 and 20
- For each of these numbers I want to increment the corresponding field in
the `count' vector

the solution with the for loop looks something like this

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

I tried using:

octave1:>count = zeros(1,20);
octave2:>count(data(:,3))++;

which returns  a vector containing all `1'

Is there a way to vectorise this task? Thanks!

Best,
Gaston
-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/Vectorisation-tp2281066p2281066.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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