MATLAB: How to create matrix with fixed sum in rows and fixed increment in elements

create matrixfixed row sumfixed steps

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
......

Best Answer

Straightforward exhaustive search which does not generate any superfluous rows:
V = 0:5:100;
Z = nan(0,3);
for n1 = V
for n2 = V
for n3 = V
if (n1+n2+n3)==100
Z(end+1,:) = [n1,n2,n3];
end
end
end
end
Z = Z/100;
This gives all 231 unique rows:
>> Z
Z =
0.00000 0.00000 1.00000
0.00000 0.05000 0.95000
0.00000 0.10000 0.90000
0.00000 0.15000 0.85000
0.00000 0.20000 0.80000
0.00000 0.25000 0.75000
0.00000 0.30000 0.70000
0.00000 0.35000 0.65000
0.00000 0.40000 0.60000
0.00000 0.45000 0.55000
0.00000 0.50000 0.50000
0.00000 0.55000 0.45000
0.00000 0.60000 0.40000
0.00000 0.65000 0.35000
0.00000 0.70000 0.30000
... lots of rows here
0.85000 0.05000 0.10000
0.85000 0.10000 0.05000
0.85000 0.15000 0.00000
0.90000 0.00000 0.10000
0.90000 0.05000 0.05000
0.90000 0.10000 0.00000
0.95000 0.00000 0.05000
0.95000 0.05000 0.00000
1.00000 0.00000 0.00000
>> size(Z)
ans =
231 3
>> size(unique(Z,'rows'))
ans =
231 3