Nested loops for double summation

6 次查看(过去 30 天)
J.Cam
J.Cam 2020-3-14
编辑: J.Cam 2020-3-20

回答(1 个)

Akira Agata
Akira Agata 2020-3-15
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(:));

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by