Nested loops for double summation

9 views (last 30 days)
J.Cam
J.Cam on 14 Mar 2020
Edited: J.Cam on 20 Mar 2020

Answers (1)

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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!