필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

generate Matrix using Combination

조회 수: 2 (최근 30일)
Raghwan Chitranshu
Raghwan Chitranshu 2019년 1월 25일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello all,
I wanted to know how to gnerate a binary matrix using combination number of rows and columns
Suppose I want to generate a matrix of 16 columns and 6 rows and wanted to maintain number of 1's in each column to be 3. Then I want to generate a code which must be using combination of 6(number of rows) and 3(number of 1's in each column). So answer is 20 combinations, in that I want to use only 16 combinations as I am having only 16 columns.
Can any one help me.
  댓글 수: 1
Gani
Gani 2019년 2월 15일
Is this something you want ?
function mBinaryMatrix = BinaryRandMatrix(nRows, nColumn, nNum)
mBinaryMatrix = zeros(nRows,nColumn);
for i = 1:nRows
rColumn = randi([1 nColumn],1,nNum); % want to have only 3 1s in each row- so give nNum = 3
mBinaryMatrix(i, rColumn) = 1;
end
end % mBinaryMatrix
Example :
mBinaryMatrix = BinaryRandMatrix(6, 16, 3);

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by