function p = primes(n)
%PRIMES Generate list of prime numbers.
%   PRIMES(N) is a row vector of the prime numbers less than or 
%   equal to N.  A prime number is one that has no factors other
%   than 1 and itself.
%
%   See also FACTOR, ISPRIME.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.10 $  $Date: 1998/05/28 22:24:17 $

if length(n)~=1, error('N must be a scalar'); end
if n <= 1, p = zeros(1,0); return, end
p = 1:n;
p(1) = 0;
for k = 2:sqrt(n)
  if p(k)
    p(k*k:k:n) = 0;
  end
end
p = p(p>0);

