How to create matrix with fixed sum in rows and fixed increment in elements
Ältere Kommentare anzeigen
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 Kommentar
Zijin Xu
am 7 Sep. 2018
Akzeptierte Antwort
Weitere Antworten (1)
Bruno Luong
am 7 Sep. 2018
Bearbeitet: Bruno Luong
am 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 Kommentare
Rik
am 7 Sep. 2018
I don't know if it is relevant, but this method is not guaranteed to give unique rows.
Bruno Luong
am 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
am 7 Sep. 2018
Stephen23
am 7 Sep. 2018
+1 Very nice.
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!