Help CenterHelp Center
Determine which array elements are prime
TF = isprime(X)
TF = isprime(X) returns a logical array containing 1 (true) where the elements of the array X are prime numbers, and 0 (false) where they are not.
X
1
(true)
0
(false)
example
collapse all
tf = isprime([2 3 0 6 10])
tf = 1x5 logical array 1 1 0 0 0
2 and 3 are prime, but 0, 6, and 10 are not.
2
3
6
10
x = uint16([333 71 99]); tf = isprime(x)
tf = 1x3 logical array 0 1 0
71 is prime, but 333 and 99 are not.
71
333
99
Input values, specified as a scalar, vector, or array of real, nonnegative integer values.
Example: 17
17
Example: [1 2 3 4]
[1 2 3 4]
Example: int16([127 255 4095])
int16([127 255 4095])
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
single
double
int8
int16
int32
int64
uint8
uint16
uint32
uint64
Usage notes and limitations:
The maximum double precision input is 2^33.
2^33
The maximum single precision input is 2^25.
2^25
The input X cannot have type int64 or uint64.
backgroundPool
ThreadPool
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Introduced before R2006a
primes
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office