select the row that contains the minimum of a column
9 views (last 30 days)
Show older comments
dolving
on 27 Jun 2014
Answered: Star Strider
on 27 Jun 2014
I have this matrix:
results =
0.0260 0.1040 0.0030 0.0246 0.0264 4.8818
0.0430 0.1040 0.0030 0.0194 0.0238 5.0857
0.0600 0.1040 0.0030 0.0164 0.0223 5.2897
0.0260 0.0870 0.0030 0.0245 0.0263 5.0856
0.0430 0.0870 0.0030 0.0194 0.0237 5.2896
0.0600 0.0870 0.0030 0.0167 0.0221 5.4936
0.0260 0.0700 0.0030 0.0246 0.0259 5.2896
0.0430 0.0700 0.0030 0.0194 0.0233 5.4937
0.0600 0.0700 0.0030 0.0164 0.0217 5.6976
0.0260 0.1040 0.0065 0.0331 0.0413 0
0.0430 0.1040 0.0065 0.0269 0.0322 4.0227
0.0600 0.1040 0.0065 0.0207 0.0264 4.4647
0.0260 0.0870 0.0065 0.0330 0.0409 0
0.0430 0.0870 0.0065 0.0268 0.0319 4.4648
0.0600 0.0870 0.0065 0.0208 0.0261 4.9067
0.0260 0.0700 0.0065 0.0330 0.0397 4.4648
0.0430 0.0700 0.0065 0.0269 0.0306 4.9067
0.0600 0.0700 0.0065 0.0208 0.0249 5.3487
0.0260 0.1040 0.0100 NaN 0 0
0.0430 0.1040 0.0100 0.0578 0.0639 0
0.0600 0.1040 0.0100 0.0445 0.0423 0
0.0260 0.0870 0.0100 NaN 0 0
0.0430 0.0870 0.0100 0.0577 0.0628 0
0.0600 0.0870 0.0100 0.0446 0.0411 0
0.0260 0.0700 0.0100 NaN 0 0
0.0430 0.0700 0.0100 0.0576 0.0584 0
0.0600 0.0700 0.0100 0.0445 0.0367 4.8460
I want to select the row that contains the minimum nonzero value of the last column.
I tried:
[minVal rowInd]=min(nonzeros(results(:,6)))
minVal =
4.0227e+003
row_idx =
10
This does give the value i want, but not the right row (it must be row_idx=11).
Any ideas would be welcome!!
0 Comments
Accepted Answer
Guilherme Coco Beltramini
on 27 Jun 2014
Use an auxiliary variable:
tmp = results(:,6); tmp(tmp==0) = NaN;
[minVal rowInd]=min(tmp)
0 Comments
More Answers (1)
Star Strider
on 27 Jun 2014
Test for the minimum first, then use find:
min6 = min(results((results(:,6) > 0),6));
ridx = find(results(:,6) == min6);
0 Comments
See Also
Categories
Find more on Numeric Types 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!