zmax = 1;
x = linspace(-zmax,zmax,500); 
y = x'*1i;
[x,y]=meshgrid(x,y);
Z = x+y;

% m = zeros(500);
% for k = 1:500
%     for p = 1:500
%         m(k,p) = escapeVelocity(Z(k,p),c,N);
%     end
% end

m = arrayfun(@(x)escapeVelocity(x,c,N),Z);

function n = escapeVelocity(z0,c,N)
% Function computes the necessary number of iterations to escape from orbit
% of z0 in Prisoner set iteration
n = 0;
zn = z0^2+c;
while(n<=N&&abs(zn)<=2)
    zn=zn^2+c;
    n=n+1;
end
end