?? isprime.m
字號(hào):
function isp = isprime(X)
%ISPRIME True for prime numbers.
% ISPRIME(X) is 1 for the elements of X that are prime, 0 otherwise.
%
% Class support for input X:
% float: double, single
%
% See also FACTOR, PRIMES.
% Copyright 1984-2004 The MathWorks, Inc.
% $Revision: 1.16.4.2 $ $Date: 2004/07/05 17:02:03 $
if isempty(X), isp = false(size(X)); return, end
if any(X(:) < 0) || any(floor(X(:)) ~= X(:))
error('MATLAB:isprime:InputNotPosInt',...
'All entries of X must be positive integers.');
end
isp = false(size(X));
n = max(X(:));
if n > 2^32
error('MATLAB:isprime:InputOutOfRange',...
'The maximum value of X allowed is 2^32.');
end
p = primes(ceil(sqrt(n)));
for k = 1:numel(isp)
isp(k) = all(rem(X(k), p(p<X(k))));
end
% p(p<1) would give an empty matrix and all([]) returns true.
% we need to correct isp for this case.
isp(X==1 | X==0)=0;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -