⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isprime.m

📁 可用于对信号的频谱进行分析,希望站长能整理好,以便大家互相学习
💻 M
字号:
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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -