How to create matrix with fixed sum in rows and fixed increment in elements
显示 更早的评论
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 个)
Bruno Luong
2018-9-7
编辑:Bruno Luong
2018-9-7
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 个评论
Rik
2018-9-7
I don't know if it is relevant, but this method is not guaranteed to give unique rows.
Bruno Luong
2018-9-7
I miss understood whereas OP wants random or all combinations. Now I fix it since the number of combinations is just 231.
Zijin Xu
2018-9-7
Stephen23
2018-9-7
+1 Very nice.
类别
在 帮助中心 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!