MATLAB: Is there any cleaner way to write this

cleaner codemapsimpler codevectors

% Note: The vector y passed into the function is a vector of labels
% containing values from 1..K. You need to map this vector into a
% binary vector of 1's and 0's to be used with the neural network
% cost function.
vectorized_y = zeros(K, m);
for i=1:m
vectorized_y(i,y(i)) = 1;
end
Related Question