Improving the speed!
Afficher commentaires plus anciens
Hey MATLAB guys,
Could someone please tell me how I can improve this code. It works pretty quick for nt_L=1:3. But, as nt_L increases, it takes forever. Any idea would be greatly appreciated.
K = 10;
nbrOfSubCarriers = 2*ones(1, K);
nt_L = 10;
nr_L = 3*ones(1, nt_L);
ulim_c = 1; % max value of each element
llim_c = 0; % min value of each element
sumlim_c = 1;
c0 = zeros(max(nr_L(:)), numel(nr_L), numel(nbrOfSubCarriers), max(nbrOfSubCarriers(:)));
for k = 1 : K
for m = 1 : nbrOfSubCarriers(k)
RMat = rand(max(nr_L(:)), numel(nr_L))*(ulim_c-llim_c) + llim_c;
Rsum = sum(RMat(:));
Rcheck = Rsum > sumlim_c;
while any(Rcheck)
RMat = rand(max(nr_L(:)), numel(nr_L))*(ulim_c-llim_c) + llim_c;
Rsum = sum(RMat(:));
Rcheck = Rsum > sumlim_c;
end
if Rsum <= sumlim_c
c0(:,:,k,m) = RMat;
else
c0(:,:,k,m) = RMat ./ Rsum; %makes the sum exactly 1
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!