how to generate a random matrix with specific condition ?

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

Huh? Please explain. CLEARLY. Give an example of what you expect.
i expect like that
first generation X = [ 1 -1 1 0 0
1 1 -1 1 1
1 1 0 1 1
0 1 0 1 1 ]
and when every generation the same column and row in matrix A i want still appear every time
So just generate a completely random matrix, and then overwrite that row and column. WTP?

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

답변 (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);

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

질문:

2016년 4월 9일

답변:

Jan
2016년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by