[讨论] 改变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