필터 지우기
필터 지우기

Creating 4D vector inside parfor

조회 수: 1 (최근 30일)
htrh5
htrh5 2015년 9월 8일
답변: Walter Roberson 2015년 9월 8일
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