필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by