Vectorizing for loops - an efficient way to do it

3 次查看(过去 30 天)
Hi, i want to know how should i vectorize two loops like this:
length=100000;
limit=8;
j=primes(9000);
j=j(randperm(limit));
d=j(randperm(limit));
X=zeros([1,length]);
X(1)=1;
for k=1:length-1
for p=0:limit-1
X(k+1)=X(k+1)+ power(-1,-p+1)*j(p+1)*X(k-p);
end
X(k+1)=rem(abs(X(k+1)),m);
end
I'm looking for an efficient way cause i've to traduce this code for gpu. I've also a big amount of data.
Thank u.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by