# in the following MATLAB Programme, I want print the resultant Matrix D with two conditions i) D has exactly one Zero ii) D with exactly two pairs like as (-x, x) and (-y, y)

1 view (last 30 days)
bala maths on 21 Feb 2022
Commented: Arif Hoq on 27 Feb 2022
A = [0 1 0 0 1 ; 1 0 1 0 0 ; 0 1 0 1 0 ; 0 0 1 0 1 ; 1 0 0 1 0]
B = [-1 -2 1 2 0];
C = perms (B);
E=C
D=C*A

Arif Hoq on 22 Feb 2022
Edited: Arif Hoq on 22 Feb 2022
A = [0 1 0 0 1 ; 1 0 1 0 0 ; 0 1 0 1 0 ; 0 0 1 0 1 ; 1 0 0 1 0];
B = [-1 -2 1 2 0];
C = perms (B);
D=C*A;
[Lia, Locb] = ismember(C,D, 'rows');
samerow=unique(Locb); % this row of D satifies the 2 condition
samerow(1)=[]; % delete the first 0 value
% rownumber=samerow(2:end);
output=D(samerow,:)
output = 10×5
0 2 -1 1 -2 0 -2 1 -1 2 -1 2 0 -2 1 -1 1 -2 0 2 2 0 -2 1 -1 2 -1 1 -2 0 1 -1 2 0 -2 1 -2 0 2 -1 -2 0 2 -1 1 -2 1 -1 2 0
bala maths on 27 Feb 2022
A = [0 1 0 0 1 ; 1 0 1 0 0 ; 0 1 0 1 0 ; 0 0 1 0 1 ; 1 0 0 1 0];
B = [-1 -2 1 2 0];
C = perms (B);
D=C*A;
[Lia, Locb] = ismember(C,D, 'rows');
samerow=unique(Locb); % this row of D satifies the 2 condition
samerow(1)=[]; % delete the first 0 value
% rownumber=samerow(2:end);
output=D(samerow,:)
In this program, suppose i want change instead of -2,2 replace -3,3 its doesn't work.
A = [0 1 0 0 1 ; 1 0 1 0 0 ; 0 1 0 1 0 ; 0 0 1 0 1 ; 1 0 0 1 0];
B = [-1 -3 1 3 0];
C = perms (B);
D=C*A;
[Lia, Locb] = ismember(C,D, 'rows');
samerow=unique(Locb); % this row of D satifies the 2 condition
samerow(1)=[]; % delete the first 0 value
% rownumber=samerow(2:end);
output=D(samerow,:)
octave:3> source("arif.m")output = [](0x5)
i think for generalized result we must use conditional statement for or if loop.
Arif Hoq on 27 Feb 2022
if you change variable A you can get the output
A = [0 2 0 0 2 ; 1 0 1 0 0 ; 0 1 0 1 0 ; 0 0 1 0 1 ; 1 0 0 1 0];

### Categories

Find more on Signal Operations in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!