フィルターのクリア

How do you find the maximum value within segments of a vector?

8 ビュー (過去 30 日間)
Deanna
Deanna 2015 年 5 月 18 日
コメント済み: Deanna 2015 年 5 月 18 日
If I have a vector with say, 10 elements, such as vec = [11 23 34 60 58 65 55 42 35 21], is there a way to find the maximum value between specified locations within the vector? For example, I want to find the location between locations 1 and 5 that has the maximum value. So, the answer would be 4.

回答 (1 件)

Image Analyst
Image Analyst 2015 年 5 月 18 日
Deanna:
You need to use the second (optional) return value of the max() function. That tells you the index where the maximum occurs . And of course just put starting and stopping indexes inside vec when you pass it to max() if you don't want it to examine the entire vector.
vec = [11 23 34 60 58 65 55 42 35 21]
[maxValue, indexOfMax] = max(vec(1:5)) % Find max in first 5 elements.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by