MATLAB: Is it possible to do this without for cycle

cyclefor

T = zeros(M,K);
for k = 1:K
T(Y==k,k) = 1;
end

Best Answer

% data
Y = [1 1 3 2 3 1 1 2] % M = numel(Y)
K = 3
% engine
T = double((Y(:) - (1:K))==0)