MATLAB: How to generate all possible weights for a constraint

portfolioweights

While I was working on my portfolio optimization I wanted to perform a numerical analysis and I wanted to generate several combinations of weights that all sum to 1. in the case of 3 assets I had this code:
for i= 0:0.1:1 for j = 0:0.1:(1-i) w_Consmr = i; w_Manuf = j; w_HiTec = 1-j-i; a = a+1; w(a,:) = [w_Consmr w_Manuf w_HiTec] ; end end
However, now I want to do this for lets say, 50 assets and making 50 for loops seems quite cumbersome, is there another way to make this more efficient ?
Sincerely, Stephan

Best Answer

Why not do something like the following?
w=rand(1,50);
w=w/sum(w);