Filter löschen
Filter löschen

Creating 4D vector inside parfor

1 Ansicht (letzte 30 Tage)
htrh5
htrh5 am 8 Sep. 2015
Beantwortet: Walter Roberson am 8 Sep. 2015
This is what I have
parfor i = 1:N/k
tti=-sqrt(N)/2+(i*k-k)/sqrt(N);
[ap,~]=meshgrid(tau/2+tti,tau/2);
[am,~]=meshgrid(tau/2-tti,tau/2);
for j = 1: N/k
ttj=-sqrt(N)/2+(j*k-k)/sqrt(N);
[~, b]=meshgrid(tau/2+tti,tau/2+ttj);
m1 = interp2(t,t,x,ap,b);
[~, b]=meshgrid(tau/2-tti,tau/2-ttj);
m2 = conj(interp2(t,t,x,am,b));
mm=real(fftshift(fft2(ifftshift( m1.*m2 ))));
W(i,j,:,:)=mm(1 : k: N,1 : k: N);
end
end
It doesn't like the way I index W, but clearly different loops do not try to overwrite each other.
The variable W in a parfor cannot be classified
How can I fix it?
I tried this:
parfor
i = 1:N/k %actually 1:4:N
tti=-sqrt(N)/2+(i*k-k)/sqrt(N);
[ap,~]=meshgrid(tau/2+tti,tau/2);
[am,~]=meshgrid(tau/2-tti,tau/2);
WW=zeros(N/k,N/k,N/k);
for j = 1: N/k %actually 1:4:N
ttj=-sqrt(N)/2+(j*k-k)/sqrt(N);
[~, b]=meshgrid(tau/2+tti,tau/2+ttj);
m1 = interp2(t,t,x,ap,b);
[~, b]=meshgrid(tau/2-tti,tau/2-ttj);
m2 = conj(interp2(t,t,x,am,b));
mm=real(fftshift(fft2(ifftshift( m1.*m2 ))));
WW(j,:,:)=mm(1 : k: N,1 : k: N);
end
W(i,:,:,:)=WW;
end
and it worked, but is it working as I want it to?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Sep. 2015
The approach you use in your second code is correct.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by