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)')';