how to setup matrix with random unique combinations
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello, in a M = 4x4 matrix I want to place 1 unique value (x=1) per column so that sum(M,2) = 1: e.g., [1 0 0 0; 0 0 0 1; 0 1 0 0; 0 0 1 0 ]
However the combination has to be randomly made.
I can use randi(4,1) to set up the first column, but the subsequent columns will have to be constrained following the first column and using "while" doesn't seem to help. Sugestions?
댓글 수: 0
채택된 답변
추가 답변 (1개)
Laura Proctor
2011년 5월 23일
If the columns and rows must all sum to 1, then try this:
M = eye(4); M = M(:,randperm(4));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Error Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!