matlab - manipulate zeros matrix to put boolean at certain position in rows -
so have matrix x of size m,10 initialized zeros.
then have vector of size m,1 contains digits 1 10
what want (hopefully in single operation no loops), each row of matrix x , vector y, want put '1' in column indexed value written in row of vector y.
here's want small example: x = [0 0 0; 0 0 0; 0 0 0]; lets y= [3; 2; 1]; expect operation return x = [0 0 1; 0 1 0; 1 0 0]
do have command can ?
x(sub2ind(size(x),y',1:numel(y)))=1
or
x((0:numel(y)-1)*size(x,2) + y')=1
Comments
Post a Comment