Creating 4D vector inside parfor

1 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2015-9-8
The approach you use in your second code is correct.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by