[討論] 改變matrix element without loop

作者: polymerase (橋南荀令過,十里送衣香)   2015-05-10 00:19:35
A=20*10 matrix of zeros.
B=20*1 matrix of integers. Values are 1~10 integer
Let's say B=[3; 1; 2; 10 .....]
以下三行有沒有辦法vectorize? Many thanks.
for i=1:20
A(i,B(i))=1
end
作者: celestialgod (天)   2015-05-10 00:53:00
我猜 A(1:20, B(:))=1應該可以
作者: sunev (Veritas)   2015-05-10 01:25:00
sub2ind

Links booklink

Contact Us: admin [ a t ] ucptt.com