i want to create a 2 dim matrix which creates 1000 rows vs 1000 columns which will look like a table, if the prime number occur output 1 in the cell and if not prime output 0

1 回表示 (過去 30 日間)
Create 2 dim matrix 0 --> 999 rows, 0 --> 999
columns Prime_matrix = zeros(1000,1000);
For i= 0 --> 1000000
If I is == prime number
X = i % 1000
Y = i / 1000
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 6 月 26 日
What have you attempted yet? Show your code and state what problem/error you are facing.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2022 年 6 月 26 日
I think this does what you want. I used 100 numbers in a 10x10 array to illustrate. Just change N to 1000.
N = 10;
Prime_matrix = reshape(isprime(0:N^2-1),N,N)'
Prime_matrix = 10×10 logical array
0 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by