I would like to get the average of some data only if the sample size is larger than two.

1 次查看(过去 30 天)
Hello,
I would like to get the average of some data only if the size of the sample is larger than two. So, if the sample size is smaller or equal to two, then it will not average. Thanks in advance.

采纳的回答

the cyclist
the cyclist 2017-2-2
if numel(x) > 2
mean_x = mean(x);
end

更多回答(1 个)

Image Analyst
Image Analyst 2017-2-2
Don't worry about it. The average of one value is the same as the value. This code works for any array of any size:
theAverage = mean(yourArray(:))
It's not really worth the extra lines of code to have it do it only in the case of 2 or more elements. Why bother? Really.

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by