MATLAB Help Center
nth prime number
nthprime(n)
nthprime(n) returns the nth prime number. nthprime acts element-wise on array inputs.
n
nthprime
example
collapse all
Find the 223rd prime number.
nthprime(223)
ans = 1409
For large prime numbers, return exact symbolic integers by using symbolic input.
n = sym(223222222); nthprime(n)
ans = 4738278383
Find the 10th, 100th, and 1000th prime numbers.
n = [10 100 1000]; nthprime(n)
ans = 29 541 7919
Generate a random prime number between the 100,000th and 200,000th prime numbers.
rng default % for reproducibility range = [100000 200000]; nthprime(randi(range))
ans = 2476423
Input, specified as a number, vector, matrix, array, or a symbolic number or array. n must be a positive integer.
Introduced in R2018a
nextprime | prevprime
nextprime
prevprime
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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
Asia Pacific
Contact your local office