How to set the row in the matrix to 0?

I have a problem with matlab where I need to find the maximum number in a matrix, and then find the next highest value in the matrix, which is not in the same row or column as the previous one.

My thought process is that I will find the maximum value in the matrix, and then find out which row and column it is in, and then set the remaining values ​​in the row and column to 0. So far, I have it.

a=rand(5) [row,column]=find(a==max(max(a))) 

I can find which row and column are max, but that's about it. Can someone help me with the next step or the best way to write this program? Thanks!

+4
source share
1 answer

What you need:

 a(row,:)=0; 

So, total:

 a=rand(5) [row,column]=find(a==max(max(a))) a(row,:)=0; [row2,column2]=find(a==max(max(a))) 

if you have negative values ​​in a , you can also do:

 a(row,:)=-inf; 
+15
source

Source: https://habr.com/ru/post/1383336/


All Articles