Find max and min values, seperated by max or min
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
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!