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!