Improving the speed!
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!