Nested loops for double summation

回答 (1 件)

Akira Agata
Akira Agata 2020 年 3 月 15 日

1 投票

How about the following?
% Example of 3-by-3 array n
n = rand(3);
% Calculate R, C, and T
R = sum(n,2);
C = sum(n);
T = sum(R);
% Calculate \chi^2
CR = (C'*R')';
S = ((n - CR/T).^2)./(CR/T);
chi2 = sum(S(:));

1 件のコメント

J.Cam
J.Cam 2020 年 3 月 17 日
Yes, thank you it worked out!

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2020 年 3 月 14 日

編集済み:

2020 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by