How I can make this matrix

1 ビュー (過去 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

カテゴリ

Find more on Matrices and Arrays in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by