Hello!
I have to create two 20x20 matrices in which the values should be either 0 or 1 and are randomly distributed.
In one matrix the chance of getting a 1 should be 90% and in the other one it should be 95%.
I don't really understand how the nested for loop works or how the values created in the for loop get assigned to the Matrix.
I would really appreciate your help!
Thanks in advance!

 採用された回答

James Tursa
James Tursa 2020 年 6 月 19 日

0 投票

You don't need loops for this. E.g.,
p = the probability
result = rand(20,20) < p; % your matrix of 0's and 1's

1 件のコメント

Sophie Stocker
Sophie Stocker 2020 年 6 月 19 日
Thank you so much! You saved my day :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by