The code shown below for drawing a Mandelbrot set, I think my code a bit redundancy to construction the Matrix M
. In Python I know there is a clean way do this,
M = [[mandel(complex(r, i)) for r in np.arange(-2, 0.5,0.005) ] for i in np.range(-1,1,0.005)]
Is there a similar way do this in Matlab?
function M=mandelPerf()
rr=-2:0.005:0.5;
ii=-1:0.005:1;
M = zeros(length(ii), length(rr));
id1 = 1;
for i =ii
id2 = 1;
for r = rr
M(id1, id2) = mandel(complex(r,i));
id2 = id2 + 1;
end
id1 = id1 + 1;
end
end
function n = mandel(z)
n = 0;
c = z;
for n=0:100
if abs(z)>2
break
end
z = z^2+c;
end
end