[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
unexpected behavior of +=
From: |
Claudio Belotti |
Subject: |
unexpected behavior of += |
Date: |
Fri, 12 Jun 2009 11:15:27 +0100 |
dear all,
A = zeros(2);
idx = [1;4;1;2];
A(idx) += 1
A =
1 0
1 1
while I was expecting to get
A =
2 0
1 1
how should I write the assignment to get the latter?
I got something similar if I do
[i,j] = ind2sub(idx)
A = sparse(i,j,1,2,2,'sum')
but I don't really need a sparse matrix ...
- unexpected behavior of +=,
Claudio Belotti <=