How do I find max values in a vector

8 ビュー (過去 30 日間)
mehmet utku ogur
mehmet utku ogur 2021 年 10 月 25 日
回答済み: KSSV 2021 年 10 月 25 日
I have a vector like this: v=[1, 3, 5, 2, -4, -3, -1, 2, 3, 1, 2, -3, -2, -4]
I need the max value of every positive sequence and min value of every negative sequence
I need a vector like this a=[5, -4, 3, -4]
thanks for help

回答 (1 件)

KSSV
KSSV 2021 年 10 月 25 日
v=[1, 3, 5, 2, -4, -3, -1, 2, 3, 1, 2, -3, -2, -4] ;
iwant = [max(v(v>0)) min(v(v>0)) max(v(v<0)) min(v(v<0))]
iwant = 1×4
5 1 -1 -4

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by