MATLAB: I have an all zero matrix ‘a’ of size m x n. In a new 2 column matrix ‘b’ I have the indices where I should replace the zero in ‘a’ with 1. Is there a way to do this without a ‘for’ loop? The m,n > 500..

matrix array

The question above.

Best Answer

sparse() is the easiest way to handle this. Another way is
A( sub2ind(size(A),B(:, 1),B(:, 2)) = 1;