```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Generating equidistributed points on the surface of a sphere ?? (error)
Date: Sun, 10 Jul 2011 18:44:09 +0000 (UTC)
Organization: Jaypee Inst of Information Tech
Lines: 50
Message-ID: <ivcrtp\$5c2\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1310323449 5506 172.30.248.38 (10 Jul 2011 18:44:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 10 Jul 2011 18:44:09 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:735727

r = 1;

phi = linspace (0, pi, 30);
theta = linspace (0, 2*pi, 30);
[phi, theta] = meshgrid(phi, theta);

x = r.*cos(theta).*sin(phi);
y = r.*sin(theta).*sin(phi);
z = r.*cos(phi);
% This Plots the sphere !
mhndl = mesh(x, y, z);

set(mhndl, ...
'EdgeColor', [0.6,0.6,0.6], ...
'EdgeAlpha', 0.5, ...
'FaceAlpha', 0.5);

axis equal
axis off

N = 10;
a = (2*r)/N;

j = -r:a:r;
k = 0:(2*pi)/N:2*pi;

for i = 0:1:N;
x = sqrt(r*r-j(i)*j(i+1))*cos(k(i+1));
y = sqrt(r*r-j(i)*j(i+1))*sin(k(i+1));
end

hold on
plot3(x, y, j,'*');

-------------------------------------------------------------------------------------------------------------
I have to implement this algorithm to evenly plot N number of points on a sphere !

repeat N times {
Choose 'z' equidistributed from [-r:r]?-r----eeedfndr
Choose 'phi' equidistributed from [0:2*Pi]
Set x = (sqrt(r*r - z*z))* cos(phi);
Set y = (sqrt(r*r - z*z))* sin(phi);
}

I get this error :
"??? Subscript indices must either be real positive integers or logicals. "

The sphere plot is correct, this error is in the for loop !