Vectorizing for loops - an efficient way to do it

3 views (last 30 days)
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.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!