1
votes

I have two matrices. One is PR1 an identity matrix and another inverse identity matrix PR2. Reference Matrix A is mentioned that can be 5x5 10x10 etc. According to that I1,I2 is created.Here it is mentioned 5x5 matrix. The logical operations start with And= PR1 AND PR2 followed by Xor= PR1 XOR PR2.

A matrix:

A =

 0     1     1     1     0     
 1     0     1     1     0     
 1     1     0     1     1     
 1     1     1     0     1    
 0     0     1     1     0   

I is identity matrix

PR1 =

 1     0     0     0     0     
 0     1     0     0     0     
 0     0     1     0     0     
 0     0     0     1     0     
 0     0     0     0     1 

PR2 =

 0     0     0     0     1     
 0     0     0     1     0     
 0     0     1     0     0     
 0     1     0     0     0     
 1     0     0     0     0  

And =

 0     0     0     0     0
 0     0     0     0     0
 0     0     1     0     0
 0     0     0     0     0
 0     0     0     0     0   

Xor =

 1     0     0     0     1
 0     1     0     1     0
 0     0     0     0     0
 0     1     0     1     0
 1     0     0     0     1

Now scan left to right of each row in And and Xor matrices. Place the first 1 as it is in the new row that is in R1 matrix. Trace for second one and do NOR operation between first one 1 row and second 1 row in A matrix in above matrix (1,5) is second 1 place so do NOR operation between 1st and 5th row place the answer in R1matrix. Similarly it has R1.

R1 =

 1     0     0     0     1
 0     0     0     0     0
 0     0     1     0     0
 0     1     0     0     0
 1     0     0     0     1

Now replace R1 to PR2 new PR2 =

 1     0     0     0     1
 0     0     0     0     0
 0     0     1     0     0
 0     1     0     0     0
 1     0     0     0     1

Again repated same process PR1 AND PR2 followed by PR1 XOR PR2

And =

 1     0     0     0     0
 0     0     0     0     0
 0     0     1     0     0
 0     0     0     0     0
 0     0     0     0     1

Xor =

 0     0     0     0     1
 0     1     0     0     0
 0     0     0     0     0
 0     1     0     1     0
 1     0     0     0     0

Now scan left to right of each row in And and Xor matrices. Place the first 1 as it is in the new row that is in R1 matrix. Trace for second one and do NOR operation between first one 1 row and second 1 row in A matrix in above matrix (1,5) is second 1 place so do NOR operation between 1st and 5th row place the answer in R2matrix.

R2=

 1     0     0     0     1
 0     1     0     0     0
 0     0     1     0     0
 0     0     0     1     0
 1     0     0     0     1

check all column has minimum one 1 and stop

2
And the question is...?kkuilla
I need this in mat lab codeMithra S
Have you searched for it? (Logical Operations)kkuilla
Logical operation I get it but R1 , R2 is problem for meMithra S
PR1 = eye(size(A,1)); I want to know how to bring PR2Mithra S

2 Answers

2
votes

PR1 AND PR2 is the same as: PR1 * PR2

C = xor(A,B)

(source).

Finding the identity matrix there is a build in function. Identity matrix (I believe that is it, I don't know why it is called "eye")

You should really google stuff, like: "xor matlab matrix". There really isn't much thinking involved with getting these. You probably put more effort into writing your question.

1
votes

That is quite straight forward

PR1 = eye(size(A,1));
PR2 = flip(PR1);
AND = and(PR1,PR2);
XOR = xor(PR1,PR2);

k = find(And~=0,1,'first');
R1 = zeros(size(A,1));
R1(k) = And(k);
idx = find(Xor~=0, 1, 'first');
R1(idx) = Xor(idx);

and if you want to do the NOR operations for row 1 and row 5 then you do

R1(1,:) = !(or(A(1,:),A(5,:)))
R1(2,:) = !(or(A(2,:),A(4,:)))
R1(4,:) = !(or(A(2,:),A(4,:))) 
R1(5,:) = !(or(A(1,:),A(5,:)))

PR2 = R1

from here repeat your process as you need.