How can I produce this matrix?

1 回表示 (過去 30 日間)
S AsZ
S AsZ 2023 年 11 月 10 日
編集済み: S AsZ 2023 年 11 月 10 日
I want to produce a m×n (m<n) matrix in which each element can only be 0 or 1 and the sum of first row must be n-(m-1) and the sum of each column must be 1. For example it can be similar to this: [1 1 0 0 1 1; 0 0 0 1 0 0; 0 0 1 0 0 0]

採用された回答

Bruno Luong
Bruno Luong 2023 年 11 月 10 日
m=6
m = 6
n=3
n = 3
j=randperm(m,n-1);
A=accumarray([2:n;j]',1,[n,m]);
A(1,setdiff(1:end,j))=1
A = 3×6
1 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1
  1 件のコメント
S AsZ
S AsZ 2023 年 11 月 10 日
編集済み: S AsZ 2023 年 11 月 10 日
Thank you 🙏🏻

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by