Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的问题是:有没有办法在 MATLAB/Octave 中对这个操作进行矢量化?
y = %a (m x 1) vector, with every entry in [1, 10] y2 = repmat(1 : 10, [m 1]); for i = 1 : m y2(i, :) = (y2(i, :) == y(i)); end
bsxfun是扩展和矢量化计算的好方法(如果有好处,它将执行多线程计算)。
bsxfun
m = 10; y = randperm(m); y2 = bsxfun(@eq,y,(1:m)')';