Is it possible to do this without for cycle?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
T = zeros(M,K);
for k = 1:K
T(Y==k,k) = 1;
end
Réponse acceptée
Jos (10584)
le 19 Mar 2018
% data
Y = [1 1 3 2 3 1 1 2] % M = numel(Y)
K = 3
% engine
T = double((Y(:) - (1:K))==0)
2 commentaires
Walter Roberson
le 20 Mar 2018
The above code requires R2016b or later. Earlier versions would need to use bsxfun()
Plus de réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!