MATLAB: How to change a whole row/column to zero in a matrix relating to a ‘greater than’ condition.

I have a random network and I would like to make the rows which have the largest sum equal to zero.
A=createsrandomnetwork(100,5)
U=sum(A)
Say the 1st and 50th number in U are the largest, I would want to make that number row and column equal to zero. I know that I could do it by noting down these numbers and then doing this:
A(1,:)=0
A(50,:)=0
A(:,1)=0
A(:,50)=0
But is there an easier, more automatic way where I could say if a value in U is greater than 5 then change the corresponding column/row to zero?

Best Answer

To set the rows/columns where the maximum sum is found:
maxsum = max(U); %I'm assuming that U is a vector here
A(U == maxsum, :) = 0;
A(:, U == maxsum) = 0;
To set rows/columns where U is greater than a value
A(U > 5, :) = 0;
A(:, U > 5) = 0;