How to choose a random number between 3 values in matrix?
16 次查看(过去 30 天)
显示 更早的评论
Hi all!
i have a matrix (m*n), i want to fill it randomly with just 3 values, for example i want to get matrix with these values : 3,6,7
the manner to choose between those values is random.
it is possible to do it?
0 个评论
采纳的回答
Walter Roberson
2022-9-6
If you have the statistics toolbox you could use randsample(). But otherwise:
choices = [3, 6, 7];
m = 4; n = 3; %for example
output = choices(randi(length(choices), m, n))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!