MATLAB: I have a marix of zeros(100*100) and i have 5 values of rows and cols in rc.(getting these values from another function). Now i want to make a new matrix B of same size as A(100*100) and want ones on that rows and cols provided by rc and zeros else

matrix manipulation

A =zeros(100,100);
[r c] =rc;
%values of rc changes everytime %example values of rc = [2 5; 3 5; 7 9; 15 69; 95 6]

Best Answer

rc = [2 5
3 5
7 9
15 69
95 6];
B = full(sparse(rc(:, 1), rc(:, 2), 1, size(A, 1), size(A, 2)));
is one way of doing it. Another way:
B = zeros(size(A));
B(sub2ind(size(B), rc(:, 1), rc(:, 2))) = 1;