How to create matrix with fixed sum in rows and fixed increment in elements
Afficher commentaires plus anciens
I would like to create a 231*3 matrix whose elements are all multiples of 0.05 and the sum of each row be equal to 1.
E.g.
0 0 1
0 0.05 0.95
0.05 0 0.95
0 0.1 0.90
0.1 0 0.90
0.05 0.05 0.90
......
1 commentaire
Zijin Xu
le 7 Sep 2018
Réponse acceptée
Plus de réponses (1)
Bruno Luong
le 7 Sep 2018
Modifié(e) : Bruno Luong
le 7 Sep 2018
s = 0.05;
n = round(1/s);
m = 3;
r = nchoosek(1:n+m-1,m-1);
z = zeros(size(r,1),1);
r = (diff([z, r, n+m+z],1,2)-1)/n
4 commentaires
Rik
le 7 Sep 2018
I don't know if it is relevant, but this method is not guaranteed to give unique rows.
Bruno Luong
le 7 Sep 2018
I miss understood whereas OP wants random or all combinations. Now I fix it since the number of combinations is just 231.
Zijin Xu
le 7 Sep 2018
Stephen23
le 7 Sep 2018
+1 Very nice.
Catégories
En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!