how to search a NXN matrix from the smallest entry to the largest, and checking to see if row = column or if the column does not equal to.
2 views (last 30 days)
Show older comments
i have a 50X50 matrix. I am trying to go through the matrix incrementing from smallest value to the largest. when even the an row number equal column number i increment a count, and when the columns and row are not equal i increment another count.
6 Comments
Image Analyst
on 21 Sep 2014
First of all, don't use min and max for variable names since they are built in functions. Secondly, your outer for loop is not even constructed properly - what is the loop iterator? Third, columns is not defined anywhere. Fourth, you get row and column but never use them anywhere. Finally, you never do anything with counter2 except set it to zero before the loop starts.
Answers (1)
Image Analyst
on 21 Sep 2014
If you're looking to count the number of elements where its row number equals its column number (which will happen only along the main diagonal), I can tell you right now that the first count will be 50, and the second count will be 50*50-50 = 2450. No sorting or scanning of the array needed.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!