How to create a weighted random number in matrix?
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to assign weighted random values to a matrix. The two values I am assigning are 0 and 1. A point needs to have a 60% probability of being assigned 0 and 40% of being assigned 1. How do I code that?
댓글 수: 0
답변 (1개)
John Petersen
2013년 8월 2일
a = rand(10); % 10x10 matrix
b = a>.6; % all elements of a > .6 are 1 all < .6 are 0
60% should be 1's, 40 % should be zeros You can test by sum(sum(b))/100
댓글 수: 2
John Petersen
2013년 8월 9일
편집: John Petersen
2013년 8월 9일
I don't see how that makes the problem different.
a = rand(1)>.6;
This says that the value of 'a' will be either 0 or 1 and has a 60% chance of being a 1.
참고 항목
카테고리
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!