>> scores = ceil(9 * rand(9, 1000) + 1); >> M = ones(9, 1000); >> for k = 1:1000 i1 = ceil(9 * rand); j = ceil(8 * rand); i2 = j + (j >= i1); M(i1, k) = 0; M(i2, k) = 0; end; >> N = sort(M .* scores); >> result = mean(N(3:9, : )); >> result