Calculate mean of a matrix columnwise if a condition is met

9 ビュー (過去 30 日間)
susman
susman 2020 年 8 月 12 日
コメント済み: hosein Javan 2020 年 8 月 12 日
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.
  2 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 8 月 12 日
Could you complete your example? What is the resulting value(s) of C for the example you shared?
susman
susman 2020 年 8 月 12 日
done!

サインインしてコメントする。

採用された回答

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
  2 件のコメント
susman
susman 2020 年 8 月 12 日
Thats absolutely perfect! Thanks
hosein Javan
hosein Javan 2020 年 8 月 12 日
you're welcome. don't mention it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by