how to generate a random matrix with specific condition ?

2 ビュー (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 4 月 9 日
回答済み: Jan 2016 年 4 月 9 日
i want to generate a random matrix in every time i want a specific row will be the same
if i have Matrix
A = [0 -1 0 0 0
1 1 -1 1 1
0 1 0 0 0
0 1 0 0 0 ]
i want to generate a random matrix and in every time the row and column which does have the ones in there entry i want to still appear in every time
  • generate a completely random matrix, and then overwrite that row and column
  4 件のコメント
John D'Errico
John D'Errico 2016 年 4 月 9 日
So just generate a completely random matrix, and then overwrite that row and column. WTP?
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 4 月 9 日
yes

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

回答 (1 件)

Jan
Jan 2016 年 4 月 9 日
A = [0 -1 0 0 0; ...
1 1 -1 1 1; ...
0 1 0 0 0; ...
0 1 0 0 0 ];
X = rand(size(A)); % Or randi?
index = (A(:) ~= 0);
X(index) = A(index);

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by