help-octave
[Top][All Lists]
Advanced

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

Increment on index expressions


From: arriquitaun
Subject: Increment on index expressions
Date: Mon, 22 Jun 2009 09:03:04 -0700 (PDT)

Hi,

I'm using octave 3.0.1 under Ubuntu 9.04 (64-bit).

I'd like to increment certain elements of a vector whose indices are given
in another vector, but I get undesired results. Say

octave:50> a=zeros(1,3);
octave:51> b=[1 2 1 1 2 1];
octave:52> a(b)++;
octave:53> a
a =

   1   1   0

However, I would expect (i.e. I'd like) to obtain
a =

   4   2   0

as the index 1 is found 4 times in b, index 2 is found 2 times in b, and
index 3 is not in b.
Using pre-increment, i.e. ++a(b), produces the same result.

I'm now using an explicit loop (for) to do this, as follows:
octave:54> a=zeros(1,3);
octave:55> for i=[1:length(b)]
> a(b(i))++;
> endfor
octave:56> a
a =

   4   2   0

However, I'd like to get rid of it since I want to do this over very large
(1e6 elements) vectors and in this case it takes a lot of time, whereas
simple operations over such large vectors are quite fast.

Is it possible to do what I intend in a fast way?


-- 
View this message in context: 
http://www.nabble.com/Increment-on-index-expressions-tp24150255p24150255.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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