Is it possible to do this without for cycle?
1 次查看(过去 30 天)
显示 更早的评论
T = zeros(M,K);
for k = 1:K
T(Y==k,k) = 1;
end
采纳的回答
Jos (10584)
2018-3-19
% data
Y = [1 1 3 2 3 1 1 2] % M = numel(Y)
K = 3
% engine
T = double((Y(:) - (1:K))==0)
2 个评论
Walter Roberson
2018-3-20
The above code requires R2016b or later. Earlier versions would need to use bsxfun()
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!