Speed up for loops for arrays
1 次查看(过去 30 天)
显示 更早的评论
Hello, Maybe someone could help me to speedup this type of for loop? I did try parfor, I did try to think of way using GPU, but it does not work with indexing.
clear;
a=7811200001;
d=1083355908;
c=zeros(1083355908,1)
parfor i = 1:d
c(i,1)=a+i;
end
0 个评论
采纳的回答
madhan ravi
2018-11-9
编辑:madhan ravi
2018-11-9
a=7811200001;
d=1083355908;
c=a+(1:d);
c=(a+1):(a+d); %edited after jan's comment
10 个评论
Jan
2018-11-9
Another hint: In a+(1:d) you create the double vector 1:d at first and then add a to each element. It is more efficient to omit the addition and create vector directly:
(a+1):(a+d)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!