Taking averages of only a few rows out of several?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2022-1-15
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 个评论
更多回答(1 个)
Image Analyst
2022-1-16
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!