How to Find First Min Value And Index it??
5 views (last 30 days)
Show older comments
Hello, I have a matrix for example looks like this
q=[5 8 1
4 1 0
2 3 1]
minq=min(q(:))
I want to index it so something like [row col]=find(q==minq)
the problem is that this will index all of the 1's. I just want it to index it the first 1. keep in mind this is just an example and I am actually working with hundreds of thousands of grid blocks and this is the only way I can get the solution to converge. Thank you so much!
0 Comments
Answers (1)
Fangjun Jiang
on 2 Sep 2016
Edited: Fangjun Jiang
on 2 Sep 2016
[row col]=find(q==minq,1,'first')
or
q=[5 8 1
4 1 2
2 3 1]
[minq,Loc]=min(q(:));
[row col]=ind2sub(size(q),Loc)
2 Comments
Fangjun Jiang
on 6 Sep 2016
If you want the second, third index, then use your original method, [row col]=find(q==minq). The returned "row" and "col" are vectors containing all the index. You can loop through the elements of "row" and "col".
See Also
Categories
Find more on Creating and Concatenating 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!