The variable in parfor cant classified

parpool(3)
parfor n = 1:N
a=n/60;
for u_p=1:length(t)
x_a(n,u_p)=sqrt(1-1i*cot(a*pi/2)) *integral(@(u) ...
rectpuls(u).*exp(1i*pi* ( cot(a*pi/2)*t(u_p)^2 -2*csc(a*pi/2)*u*t(u_p) +cot(a*pi/2)*u.^2 )) ,- HalfDur,HalfDur );
end
end
Pretty sure I do not access the same location, but I might be wrong. What am I doing wrong?
on a side note, how can I write that inner loop better? i couldnt vector it

 Réponse acceptée

Walter Roberson
Walter Roberson le 12 Juil 2015

1 vote

parfor requires that it be obvious that the same location cannot be written to multiple times.
You should write your output to a vector indexed just by n. You can then reshape the vector afterwards.

5 commentaires

htrh5
htrh5 le 12 Juil 2015
so im going to have to copy an array around each loop. thats annoying.
i have another question: forget about parfor, how would i get rid of the inner loop?
The change to your code would be minor:
parpool(3)
parfor n = 1:N
a=n/60;
x_au = zeros(length(t),1);
for u_p=1:length(t)
x_au(u_p) = sqrt(1-1i*cot(a*pi/2)) *integral(@(u) ...
rectpuls(u).*exp(1i*pi* ( cot(a*pi/2)*t(u_p)^2 -2*csc(a*pi/2)*u*t(u_p) +cot(a*pi/2)*u.^2 )), -HalfDur, HalfDur );
end
x_a(n,:) = x_au;
end
With regards to getting rid of the inner loop: Is HalfDur certain to be < 1/2, or is it certain to be > 1/2 ? Either way there is a closed form for the integral, but the forms differ in how messy they are to write out. As there is a closed form, the u_p loop can be vectorized.
htrh5
htrh5 le 12 Juil 2015
rectpuls inside the integral could have been anything, so I am guessing that integral() cannot be evaluated with a vector parameter to produce a vector output?
Walter Roberson
Walter Roberson le 12 Juil 2015
Consider using the ArrayValued option of integral()
htrh5
htrh5 le 12 Juil 2015
Thanks, that's it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by