select the row that contains the minimum of a column
조회 수: 7 (최근 30일)
이전 댓글 표시
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
채택된 답변
Guilherme Coco Beltramini
2014년 6월 27일
Use an auxiliary variable:
tmp = results(:,6); tmp(tmp==0) = NaN;
[minVal rowInd]=min(tmp)
댓글 수: 0
추가 답변 (1개)
Star Strider
2014년 6월 27일
Test for the minimum first, then use find:
min6 = min(results((results(:,6) > 0),6));
ridx = find(results(:,6) == min6);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!