Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
Deanna
Deanna le 18 Mai 2015
Commenté : Deanna le 18 Mai 2015
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.

Réponses (1)

Image Analyst
Image Analyst le 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.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by