find second minimum in a row in matlab without sorting
이전 댓글 표시
find second minimum in a row in matlab without sorting.
excluding zero
example A = [ 3.5 2 1.6 1.456 0 1.9 2.6 ; 3.8 2.6 3.9 0 6 1.564 0 ]
댓글 수: 3
the cyclist
2019년 10월 16일
Sounds like homework. What have you tried?
Nitin Sapre
2019년 10월 17일
Adam Danz
2019년 10월 17일
Why avoid sorting?
채택된 답변
추가 답변 (2개)
Ekaterina Sadovaya
2019년 10월 18일
You can exclude the first minimum. So, for example for the first row it will be
A1 = A(1,:);
[first_min_value, index] = min(A1);
A1(index) = [];
second_min_value = min(A1);
댓글 수: 7
...or a variation of (hint)
max(mink(A,2))
Nitin Sapre
2019년 10월 18일
Prior to searching for the 2nd min, you could replace all 0s with NaN or Inf. I still think this is homework since there's no explanation as to why sorting is not allowed so I'll only make that suggestion and you can figure out the rest.
hint: use ==
Nitin Sapre
2019년 10월 18일
Adam Danz
2019년 10월 18일
No need for a loop.
Here's a similar example.
x = randi(20,8,8) %Random integers between 1 and 20
% Replace all values greater than the mean.
x(x > mean(x(:))) = NaN;
Nitin Sapre
2019년 10월 19일
Nitin Sapre
2019년 10월 19일
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!