Effacer les filtres
Effacer les filtres

Producing 100 prime number in a vector

5 vues (au cours des 30 derniers jours)
Abhishek
Abhishek le 27 Oct 2022
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

Réponse acceptée

David Hill
David Hill le 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by