Calculate mean of a matrix columnwise if a condition is met

9 次查看(过去 30 天)
I am stuck on a small coding issue.
I have a big matrix "A" and a scalar value "b" and I want to determine,
Expected value = Mean ( A -b) if A < b
for example if,
A = [10 10 10;10 5 5;10 5 5]
b = 10
C = b - A
C = [0 0 0; 0 -5 -5; 0 -5 -5]
Calculate mean = Expectation [C / (A<b ]
calculations of mean should be columnwise.

采纳的回答

hosein Javan
hosein Javan 2020-8-12
A = [10 10 10;10 5 5;10 5 5]
b = 10
C = b - A
C(A>=b) = nan % replace all data out of specified range by nan
mean(C,'omitnan') % mean columns omitting nan

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by