Taking averages of only a few rows out of several?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Voss
il 15 Gen 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 Commenti
Più risposte (1)
Image Analyst
il 16 Gen 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!