Taking averages of only a few rows out of several?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a data set that is 6X100. I need to take the average of the first three rows for all 100 and then of the last three rows for all 100 columns. How do I take averages of only a few rows?
0 commentaires
Réponse acceptée
Voss
le 15 Jan 2022
A = (1:6).'.*(1:100)
mean(A(1:3,:))
mean(A(1:3,:),'all')
mean(A(end-2:end,:))
mean(A(end-2:end,:),'all')
0 commentaires
Plus de réponses (1)
Image Analyst
le 16 Jan 2022
That's kind of ambiguous. Do you want a mean from each row, so you'll get 3 values? Or do you want all 300 values to be averaged into a single value.
A = (1:6).'.*(1:100)
% Get 3 means -- one for each row.
meanFirst3 = mean(A(1:3,:), 2)
meanLast3 = mean(A(end-2:end,:), 2)
% Get 1 mean covering all 3 rows
meanFirst3 = mean2(A(1:3,:))
meanLast3 = mean2(A(end-2:end,:))
If you don't have mean2 (in the Image Processing Toolbox), you can use mean(A(1:3,:), 'all').
0 commentaires
Voir également
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!