フィルターのクリア

Producing 100 prime number in a vector

5 ビュー (過去 30 日間)
Abhishek
Abhishek 2022 年 10 月 27 日
回答済み: David Hill 2022 年 10 月 27 日
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

採用された回答

David Hill
David Hill 2022 年 10 月 27 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by