When I change this code as below, then it works but when I uncomment the x,y and z statements, it gives error.
%for sourceNo=1:P
    for m=0:N-1
        AF(m+1,1:P) = exp(-1i*k*a*sind(u(1:2)-phi_n(m+1)));
        % x(m+1,1:P) = abs (AF(m+1,sourceNo))*sin(u(1:2))*cos(u(3:4));
        % y(m+1,1:P) = abs(AF(m+1,sourceNo))*sin(u(1:2))*sin(u(3:4));
        % z(m+1,1:P) = abs(AF(m+1,sourceNo))*cos(u(1:2));
    end
%end


