Borrar filtros
Borrar filtros

Creating 4D vector inside parfor

1 visualización (últimos 30 días)
htrh5
htrh5 el 8 de Sept. de 2015
Respondida: Walter Roberson el 8 de Sept. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Sept. de 2015
The approach you use in your second code is correct.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by