Find max and min values, seperated by max or min
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a large set of numbers and need to find two minimum values and two maximum values. However it shouldn't just be the two absolute max and min values they need to be seperated by a max or min value. So max,min,max,min.
댓글 수: 0
채택된 답변
KSSV
2020년 4월 20일
편집: KSSV
2020년 4월 20일
Let A be your array.
[val1,idx1] = max(A) ;
A(idx1) = NaN ;
[val2,idx2] = max(A) ;
if idx1 > idx2
[val3,idx3] = min(A(idx2:idx1)) ;
else
[val3,idx3] = min(A(idx1:idx2)) ;
end
[val4,idx4] = min(A(idx2:end)) ;
Also read about findpeaks. Also you can sort array and get it.
댓글 수: 6
KSSV
2020년 4월 20일
clc; clear all ;
A=[1;3;1.2;1.2;0.7;0.6;0.61;1;4;7;1.2;0.5];
B = A ;
[val1,idx1] = max(A) ;
A(idx1) = NaN ;
[val2,idx2] = max(A) ;
while (abs(idx1-idx2)==1)
A(idx2) = NaN ;
[val2,idx2] = max(A) ;
end
if idx1 > idx2
[val3,idx3] = min(A(idx2:idx1)) ;
else
[val3,idx3] = min(A(idx1:idx2)) ;
end
[val4,idx4] = min(A(idx2:end)) ;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fixed-Point Overview에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!