MATLAB: Loop on matrices inversion with gpu

gpu matrix inversion dimension arrayfun

Hi everybody ! I'm a begginer with matlab gpu fonctionalities. I try to do many matrices inversion with gpu (see code below), and it doesn't work, with error code 'matrix dimensions must agree'. Could you indicate me a way for solving my problem ? Many thanks !
% basic script
vFT= % some array, size M*N
vFT = gpuArray(vFT);
pFT = zeros(M,N,'gpuArray');
Mat= %some N*N*M matrix
Mat=gpuArray(Mat);
[vFT]=arrayfun(@ComputeVelocity,pFT,Mat,M,N);
% function ComputeVelocity
function [ vFT ] = ComputeVelocity(pFT,Mat,M,N)
for k=1:M/2+1
u = Mat(:,:,k)\pFT;
vFT(k,:) = u(1:N);
end
end

Best Answer

Your code has too many errors to be certain what you're trying to do. If you're just trying to calculate Mat(:,:,k)\pFT for every k, then this is one way you could do it:
A=gpuArray(Mat); B=gpuArray(pFT);
At=pagefun(@transpose,A);
AtA=pagefun(@mtimes,At,A); AtB=pagefun(@mtimes,At,B);
result=pagefun(@mldivide, AtA,AtB)