How to take a mean from a range of values

6 vues (au cours des 30 derniers jours)
Sophie
Sophie le 4 Mai 2023
Commenté : Sophie le 4 Mai 2023
Hi, I have variables that look something like this (simplified):
x = [1 2 3 4 5]
y = [10 20 30 40 50]
I then plotted x and y. Now, I want to take the mean value of y from x = 2.5-4.5.
I'm not sure how to take a mean of a range of values.
Thanks!

Réponse acceptée

the cyclist
the cyclist le 4 Mai 2023
x = [1 2 3 4 5];
y = [10 20 30 40 50];
xInRange = (x>2.5) & (x<=4.5);
mean(y(xInRange))
ans = 35

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots 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