Checking if minimum of a matrix occurs on the diagonal
    7 views (last 30 days)
  
       Show older comments
    
For a matrix, I would like to check if the minimum value of each row is found on the diagonal. The minimum value can occur more than once within a row. Since the min command returns the index of the first occurrence of the minimum, min can miss later occurrences on the diagonal, as follows:
testMatrix = [     1     3     5     1
     2     0     4     6
     3     9     2     7
    -2     9     4    -2];
[~, iMin] = min(a)
iMin =
   4     2     3     4
How can I check if the row minimum is found on the diagonal? I am working with a very large matrix in reality, so I would like to avoid looping down the rows.
2 Comments
Accepted Answer
  Julian Hapke
      
 on 4 Oct 2018
        with a slight modification of Adams comment:
diag(testMatrix) == min(testMatrix , [], 2)
min accepts the dimension in which you want the minimum, in this case you want the minimum of each row, so in direction 2 and check against the diagonal of the matrix
More Answers (0)
See Also
Categories
				Find more on Operating on Diagonal Matrices in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

