Taking averages of only a few rows out of several?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Voss
am 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 Kommentare
Weitere Antworten (1)
Image Analyst
am 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 Kommentare
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!