Clear Filters
Clear Filters

Producing 100 prime number in a vector

5 views (last 30 days)
Hi,
I want to generate a vector in which I could check that vector for prime numbers using isprime(vector). So far I have been able to get the get a vector, but it does not give the number which are prime. Instead it gives out a vector where all the prime numbers are replaced by one and non prime with zero.
p=(2:1:600)
y=isprime(p)
I used the following code.
Thanks in advance

Accepted Answer

David Hill
David Hill on 27 Oct 2022
p=(2:1:600);
p(isprime(p))
ans = 1×109
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113
primes(600)%better and faster
ans = 1×109
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!