MATLAB: Find all possible unique combinations of weights of 3 assets

combinatoricsMATLAB

I need to find all possible weight combinations of 3 assets. Each one can take values from 1 to 100 with an increment of 1 (1, 2, 3 etc.). All 3 weights should sum up to 100. So I should get smth like:
0 1 99
0 2 98
100 0 0
I know that mathematically i should have 5151 combinations in total. But whatever I try (including what i found on the forum) just consistently produces fewer combinations.
Could please someone help

Best Answer

Here's a brute force and ignorance method:
c = 0;
n = [];
for i=0:100
for j=0:100
for k=0:100
if i+j+k==100
c=c+1;
n = [n; i, j, k];
end
end
end
end