How do you find the maximum value within segments of a vector?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Image Analyst
am 18 Mai 2015
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.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!