MATLAB: How to iterate three variables having sum one always

iterationnested loops

Hi I want to do an empirical study in MATLAB where I have three variables over the range 0 to 1 with a constraint that the sum of three variables should be always 1. I want to consider all possible values and then calculate my statistics based on these three variable every time. All the possible values are listed in attached file (sum1). I have tried different things but still didn't get it
P1= 0; P2 = 0;
for k = 1:10;
P3 = 1;
for i = 1:10
P3 = P3 - 0.1;
P2 = 1 - P3 - P1;
sum = P1 + P2 + P3;
if P2 < 0
break;
end
fprintf('i = %d \t j = %d \t P1 = %f \t P2 = %f \t P3 = %f \t sum = %f \n', i, j, P1, P2, P3, sum);
end
%fprintf('\n')
P1= P1 + 0.1;
end
or this
counter = 0;
P1= 0;
for k = 1:10;
P2 = 0;
for j = 1:10;
P3 = 1;
for i = 1:10
counter = counter + 1;
sum = P1 + P2 + P3;
if sum > 1
break;
end
fprintf('i = %d \t j = %d \t P1 = %f \t P2 = %f \t P3 = %f \t sum = %f \n', i, j, P1, P2, P3, sum);
P3 = P3 - 0.1;
end
P2 = P2 + 0.1;
end
P1 = P1 + 0.1;
end
fprintf('counter = %d \n', counter)
I have tried other things like i < j and j < k. or j < k + h with with two loops. Any help will be appreciated.

Best Answer

for P1 = 0 : .1 : 1
for P2 = 0 : .1 : 1-P1
P3 = 1 - P1 - P2;
.... do whatever ...
end
end