How I can make this matrix

조회 수: 2 (최근 30일)
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2021년 7월 29일
A=[ 1 1 1 1 0 0 0 0 0 0; 1 0 0 0 1 1 1 0 0 0; 0 1 0 0 1 0 0 1 1 0; 0 0 1 0 0 1 0 1 0 1; 0 0 0 1 0 0 1 0 1 1] How I can make this matrix in a single command.
  댓글 수: 1
Monika Jaskolka
Monika Jaskolka 2021년 7월 29일
You already have it in a single command.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shravan Kumar Vankaramoni
Shravan Kumar Vankaramoni 2021년 8월 2일
Hi,
The given matrix has equal number of ones in each row or sum of elements in each row is same. If you are looking for such a matrix, it cannot be done in a single command. Refer the code below.
x = [1 0 0 1 1]; %x
n = numel(x); %how many x?
arow = x(randperm(n));
shiftvals = randperm(n) - 1;
p = zeros(n, n);
for K = 1 : n
p(K,:) = circshift(arow, [0 shiftvals(K)]);
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by