필터 지우기
필터 지우기

how to construct 4x2 matrix taking value 0 and 1 randomly? No rows should be repeated.

조회 수: 1 (최근 30일)
for example 4x2 matrix, the output should be [1 0;1 1;0 1; 0 0]. In this matrix no rows are repeated. I uses the code randi([0,1],4,2). I got 4x2 matrix but getting repeated row like [1 0;1 1;1 0; 0 0].Here, row1 and row3 are same, which is not acceptable.
please help to construct the matrix without any repeation of rows.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2017년 1월 18일
편집: Andrei Bobrov 2017년 1월 18일
One of ways:
dec2bin(0:3)-'0'

James Tursa
James Tursa 2017년 1월 18일
result = dec2bin(randperm(4)-1) - '0';

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by