Cody

Problem 885. Create logical matrix with a specific row and column sums

Solution 2533683

Submitted on 13 Jun 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
n = 10; c = 3; M = createMatrix(n,c); assert( all(sum(M,1)==c) && all(sum(M,2)==c) && all(diag(M)==0) && ... islogical(M) && ismatrix(M) && all(size(M)==n) )

Undefined function 'intlinprog' for input arguments of type 'double'. Error in createMatrix (line 12) x = intlinprog(f, 1:n^2, [], [], A, b, zeros(n^2,1), ones(n^2,1)); Error in Test1 (line 2) M = createMatrix(n,c);

2   Fail
n = 2; c = 1; M = createMatrix(n,c); assert( all(sum(M,1)==c) && all(sum(M,2)==c) && all(diag(M)==0) && ... islogical(M) && ismatrix(M) && all(size(M)==n) )

Undefined function 'intlinprog' for input arguments of type 'double'. Error in createMatrix (line 12) x = intlinprog(f, 1:n^2, [], [], A, b, zeros(n^2,1), ones(n^2,1)); Error in Test2 (line 2) M = createMatrix(n,c);

3   Fail
n = 10; c = 9; M = createMatrix(n,c); assert( all(sum(M,1)==c) && all(sum(M,2)==c) && all(diag(M)==0) && ... islogical(M) && ismatrix(M) && all(size(M)==n) )

Undefined function 'intlinprog' for input arguments of type 'double'. Error in createMatrix (line 12) x = intlinprog(f, 1:n^2, [], [], A, b, zeros(n^2,1), ones(n^2,1)); Error in Test3 (line 2) M = createMatrix(n,c);

4   Fail
n = 100; c = 50; M = createMatrix(n,c); assert( all(sum(M,1)==c) && all(sum(M,2)==c) && all(diag(M)==0) && ... islogical(M) && ismatrix(M) && all(size(M)==n) )

Undefined function 'intlinprog' for input arguments of type 'double'. Error in createMatrix (line 12) x = intlinprog(f, 1:n^2, [], [], A, b, zeros(n^2,1), ones(n^2,1)); Error in Test4 (line 2) M = createMatrix(n,c);

5   Fail
n = randi([2 20]); c = randi([1 n-1]); M = createMatrix(n,c); assert( all(sum(M,1)==c) && all(sum(M,2)==c) && all(diag(M)==0) && ... islogical(M) && ismatrix(M) && all(size(M)==n) )

Undefined function 'intlinprog' for input arguments of type 'double'. Error in createMatrix (line 12) x = intlinprog(f, 1:n^2, [], [], A, b, zeros(n^2,1), ones(n^2,1)); Error in Test5 (line 2) M = createMatrix(n,c);

6   Fail
n = randi([20 100]); c = randi([10 n-1]); M = createMatrix(n,c); assert( all(sum(M,1)==c) && all(sum(M,2)==c) && all(diag(M)==0) && ... islogical(M) && ismatrix(M) && all(size(M)==n) )

Undefined function 'intlinprog' for input arguments of type 'double'. Error in createMatrix (line 12) x = intlinprog(f, 1:n^2, [], [], A, b, zeros(n^2,1), ones(n^2,1)); Error in Test6 (line 2) M = createMatrix(n,c);

Suggested Problems

Community Treasure Hunt

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

Start Hunting!