Clear Filters
Clear Filters

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)
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

Accepted Answer

Arif Hoq
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
  6 Comments
bala maths
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!