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

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-3-19

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by