Re-arrange matrix based on index on GPU using arrayfun

2 views (last 30 days)
Tutu
Tutu on 12 Jul 2019
Commented: Tutu on 2 Aug 2019
Hi,
I want to re-arrange a two dimensions frequency domain x,y to p=sqrt(x^2+y^2) on GPU. I can do so with the code below. However, it it is pretty slow for my application (2 seconds). I have read about arrayfun but could not make it work for my purpose. Any help is much appreciated.
nx=200;
Nx=floor(nx/2);
ny=100;
Ny=floor(ny/2);
t=200;
Nt=floor(t/2);
A=gpuArray(single(rand(nx,ny,t)));
A=fft2(A);
A=A(1:Ny,1:Nx,:);
freqx=0:1/nx:1/2-(1/nx);
freqy=0:1/ny:1/2-(1/ny);
A=fft(A,nz,3);
G=gpuArray(single(zeros(Ny*Nx,Nt+1)));
for ii=1:Nx
for jj=1:Ny
G((ii-1)*ny+jj,1)=sqrt(freqx(1,ii)^2+freqy(1,jj)^2);
G((ii-1)*ny+jj,2:end)=abs(squeeze(A(jj,ii,1:Nt)));
end
end
Ma=max(G(:,1));
bin=Ma/100;
Y=gpuArray(single(zeros(100,Nt+1)));
for ii=1:100
loik= (G(:,1)>=(bin*(ii-1)) & G(:,1)<(bin*(ii)));
Y(ii,:)=mean(G(loik,:));
end
Any help is appreciated.
Thanks
  4 Comments
Tutu
Tutu on 2 Aug 2019
Thanks Walter Roberson for your answers. I will accept your repply as the answer to this question.

Sign in to comment.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!