here,part of my following code.
clcclear allA=8;B=12;C=10;for ii=1:C; for x=1:2:A-1; %make first random matrice
[vals RandomMatriceA(x,:,ii)]=sort(rand(1,B),2); done=false; while ~done, %make row of second random matrice
NewRowRandomMatriceB=randi([0 2],1,B); %Make sure sum all element per row in RandomMatriceB <=11
done=sum(NewRowRandomMatriceB)<12; end RandomMatriceB(x,:,ii)=NewRowRandomMatriceB; ... end for h=2:2:A; doneA=false; while ~doneA, [vals RandomMatriceA(h,:,ii)]=sort(rand(1,B),2); doneB=false; while ~doneB, NewRowRandomMatriceB=randi([0 2],1,B); doneB= sum(NewRowRandomMatriceB)<12; end RandomMatriceB(h,:,ii)=NewRowRandomMatriceB; ... end ...
when I tried to use profile viewer to check my code. above part that makes my code took longer time. so, I want suggestion to speed my above code, specially in "randi"
Best Answer