Is it possible to do this without for cycle?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mr M.
il 19 Mar 2018
Commentato: Walter Roberson
il 20 Mar 2018
T = zeros(M,K);
for k = 1:K
T(Y==k,k) = 1;
end
Risposta accettata
Jos (10584)
il 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 Commenti
Walter Roberson
il 20 Mar 2018
The above code requires R2016b or later. Earlier versions would need to use bsxfun()
Più risposte (1)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!