%Set up row names (teams), column headers (stats) and data matrix (x) n=length(teams); simpcount = 0; simpteams = {}; for i=1:n for j=(i+1):n %Check if simpson's paradox condition hold for teams i and j if (x(i,1)>x(j,1) && x(i,2)x(j,2) && x(i,3)>x(j,3)) simpcount = simpcount + 1; simpteams(simpcount,:) = [teams(i) teams(j)]; end end end if simpcount == 0 disp('There are no cases of Simpson''s Paradox'); else disp(sprintf('There are %d cases of Simpson''s Paradox', simpcount)); simpteams end