Matlab - How to create logical array matrix without looping -
this question has answer here:
- creating indicator matrix 5 answers
i want following:
y = [1; 2; 3]; x = repmat(1:10, 3, 1); i=1:3 x(i,:) = x(i,:) == y(i); end so end
x = 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 is there way without looping?
if start 1:10 vector, using bsxfun:
y = [1; 2; 3]; x = bsxfun(@eq, y, 1:10); otherwise repmat:
y = [1; 2; 3]; x = repmat(1:10, 3, 1); x = repmat(y, 1, size(x,2)) == x; (or ones suggested leo.)
Comments
Post a Comment