I want to generate all possible combinations of 3*3 matrix, where the sum of all elements of this matrix equal 10.

2 views (last 30 days)
I want to generate all possible combinations of 3*3 matrix, where the sum of all elements of this matrix equal 10.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 8 Aug 2018
Edited: Fangjun Jiang on 8 Aug 2018
Then you probably mean "one way" to generate the matrix, not "all possible combinations". The one way below does not even consider any negative numbers
a=rand(3);
a=a*10/sum(a(:))
sum(a(:))

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!