Is it possible to do this without for cycle?

1 visualizzazione (ultimi 30 giorni)
T = zeros(M,K);
for k = 1:K
T(Y==k,k) = 1;
end

Risposta accettata

Jos (10584)
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
Walter Roberson il 20 Mar 2018
The above code requires R2016b or later. Earlier versions would need to use bsxfun()

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 19 Mar 2018

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by