I love this kind of problems. First of all, Matlab comes with a debugger that tell you in which part you are losing your time (It's called Run and Time). After running it, it says that the while loop is really slow, so you have to search one way to make the condition succesful in the first attemp. I have try a solution with some other modifications like the if condition which is achieve by the while.
tic
K = 10;
mult_nbrOfSubCarriers = 2;
nbrOfSubCarriers = mult_nbrOfSubCarriers*ones(1, K);
nt_L = 10;
nr_L = 3*ones(1, nt_L);
ulim_c = 1;
llim_c = 0;
sumlim_c = 1;
max_nr_L = max(nr_L(:));
numel_nr_L = numel(nr_L);
c0 = zeros(max_nr_L, numel_nr_L, K, mult_nbrOfSubCarriers);
sumlim_c2 = (sumlim_c - llim_c)/(ulim_c-llim_c);
for k = 1 : K
for m = 1 : nbrOfSubCarriers(k)
RMat = rand(max_nr_L, numel_nr_L);
sum_RMat = sum(RMat(:));
if sum_RMat > sumlim_c2
RMat = RMat./sum_RMat.*sumlim_c2;
end
c0(:,:,k,m) = RMat.*(ulim_c-llim_c) + llim_c;
end
end
toc
Best Answer