How to choose a random number between 3 values in matrix?
조회 수: 8 (최근 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!