MATLAB: Create array

array

Hi considering I want to make a a 3×6624 matrix of random numbers (>0 and <1) but I want the sum of each column of the3 numbers to add up to 1. Any help?
Thanks

Best Answer

a=zeros(3,6624);
for b=1:size(a,2)
c(1)=rand/3;
c(2)=rand/3;
c(3)=1-c(1)-c(2);
cr=randperm(3);
a(:,b)=[c(cr(1));c(cr(2));c(cr(3))];
end