if i have matrix and i want to generate a random matrix with specific rule ?

조회 수: 14 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 5월 3일
편집: Walter Roberson 2024년 11월 19일 19:26
if i have this matrix
Full_Matrix = [ 1 1 0 1 0 1
0 0 0 0 0 0
0 1 0 0 0 0
0 1 0 0 0 0
1 1 0 1 1 1]
and i want to generate a random matrix X with the same size of Full_matrix and after that
i want to copy the row and column in Full_Matrix that have ones like
[ 1 1 0 1 0 1 ]
[ 1 1 0 1 1 1 ]
and the column
[ 1
0
1
1
1 ]
and put them in the same position in the new matrix like that
if
X = [ 1 0 1 0 0 1
0 0 1 0 1 0
1 0 1 0 0 1
1 1 1 0 0 1
0 1 1 0 1 0 ]
and after copying from Full_Matrix the X matrix will be like that
X = [ 1 1 0 1 0 1
0 0 1 0 1 0
1 1 1 0 0 1
1 1 1 0 0 1
1 1 0 1 1 1 ]
  • i want a function to do this operation because the Full_Matrix will be change

답변 (1개)

BhaTTa
BhaTTa 2024년 11월 19일 14:39
Hey @Firas Al-Kharabsheh, I understand that you want to overlap "Full_Matrix" on matrix "X" , you can achieve it by looping through each indices and and add the below logic:
if Full_Matrix(i,j)+X(i,j)>=1
X(i,j)=1;
else
X(i,j)=0;
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