生成在Matlab加权随机布尔矩阵

编程入门 行业动态 更新时间:2024-10-27 18:27:08
本文介绍了生成在Matlab加权随机布尔矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要生成一个 5×5 矩阵MatLab的是仅由1和0的,但是我希望能够设置任何值,是一个1。我希望这是的可能性有90%的几率任何元素将是1,而不是0。

I want to generate a 5x5 matrix in MatLab that is made of only 1s and 0s, however I want to be able to set the likelihood of any value being a 1. I want there to be a 90% chance any element will be a 1 rather than a 0.

不过,我不想在那里只是永远是90%1和10%0。我只是想这是更可能发生的情况。例如。我还是希望它能够为全0,或50%1和50%0,只是不太可能。

However I do NOT want there to just always be 90% 1s and 10% 0s. I just want this to be the more likely case. E.g. I still want it to be possible to be all 0s, or 50% 1s and 50% 0s, just very unlikely.

感谢您的任何帮助。

推荐答案

我已经写的很清楚,简单的code明白了:

I've wrote a very clear and simple code to understand:

mat5x5 = rand(5); chanse_of_1s=.90% probability for 1s, just change it. chanse_of_0s=.10% probability for 0s, just change it. mat5x5 = arrayfun(@(x)sum(x >= cumsum([0, chanse_of_0s, chanse_of_1s])), mat5x5)-1

只是恰克的chanses!

just chage the chanses!

更多推荐

生成在Matlab加权随机布尔矩阵

本文发布于:2023-11-30 06:28:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649022.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔   矩阵   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!