12 Jun 2012 @JUAN CARDENAS
n = floor((-1+sqrt(1+8*p))/2);
m=-(n-2*p+n.*(n+1));

Very good solution for using any p but
I think you were missing a '-'sign for your definition of m. (can be seen when plotting the Zernike-Polynomials)

This code is extremely useful.
I'm not particularly good in using matlab but i had no trouble understanding how to use it (although it took me a good FIVE minutes).
So Five stars for sure for doing EXACTLY what it says on the box, nothing more and nothing less. You guys should be ashamed for rating less then 5 stars.
For others, to get rid of the gaps I used
FilteredResult=medfilt2(Result, [3 3])
This is how I used this code
(you will now notice i'm no good at matlab)
GGG(1:355,1:355)=0;
xxx(1:355,1:355)=0;
y=rand(1,150);
y=y*50
jj=1;
for j=1:150;
AAA=MidpointCircle(xxx,j,177,177,y(1,jj));
GGG=AAA+GGG;
jj=jj+1;
end;
GGG=medfilt2(GGG, [3 3])
image (GGG)

this is a coding to draw a circle.
i using the same code but i looping it with reduce the radius.
let say, my radius is 7, I try looping it by draw radius with 7, and then 6, and then 5 and so on until it become 0. It really fill in a lot of space but the problem is still got some space is empty.
My problem now is I want to fill in all the area inside the circle. So, any idea to solve this problem? Thank you

got it working.
i = the pixel value for coordinate (1,1).
radius = radius of the circle.
xc and yc = center coordinate of the circle.
value = the pixel value for the circle.
extra note: the value for xc and yc must be larger than radius.
thanks author, i've been searching for this kind of function.

Comment only