Sunday, September 27, 2009

faster way to sum desired matrix elements in matlab

Just works



g = rand(5)
p = blkdiag(1,1,0,1,1)

index = find(p~=0)

sum(g(index))

No comments: