Displaying lowest values in an array with their respective row numbers?

2 views (last 30 days)
Hello, I have been able to find the mins, but am not well versed in MatLab and cannot figure out how to state the row number for the min values.Ex: Program asks user to give an array, then takes the min of each column using for loops(required). I can then display the mins as such:[1 8 2 4 3]. If the matrix is, say [1 9 3 4 5;9 8 2 6 3] I am attempting to get to where I can display this below. Any help appreciated, although Im on a tight schedule, so the sooner the better. Thank you!
1 2 2 1 2
1 8 2 4 3

Answers (1)

Star Strider
Star Strider on 13 Oct 2015
If you are looping through each column in your loop, and if there is only one value of the minimum in each column I would use the min function with two outputs, the second being the first index of the minimum that occurs in the vector:
[colmin,idx] = min(column);
If you have more than one minimum value, use the find function:
idxv = find(column == min(column));
Experiment with these to get the result you want.

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!