Matrix with nested for loops
15 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
James Tursa
2020-6-19
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!