How to make a matrix only with 2 types of numbers randomly
3 次查看(过去 30 天)
显示 更早的评论
Hello,
It may sound a silly question but i cannot think in the desired solution. I need to make a matriz 1:24 only with values that might be 5 or 10? How can i make it randomly?
Example of the desired solution: [10 5 10 5 5 5 10 10 5 10 10 10 10 10 10 5 5 5 5 5 10 5 10 10]
0 个评论
采纳的回答
Wayne King
2012-12-18
编辑:Wayne King
2012-12-18
x = rand(24,1);
y = zeros(size(x));
y(x<0.5) = 10;
y(x>0.5) = 5;
The above gives you 10's and 5's occurring with equal probability.
更多回答(1 个)
Image Analyst
2012-12-18
Here's another way:
a = 5 * (randi(2, 1, 24)-1) + 5
3 个评论
Image Analyst
2012-12-18
If you have the Image Processing Toolbox you can use the new imquantize() function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!