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)

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Arif Hoq
Arif Hoq le 22 Fév 2022
Modifié(e) : Arif Hoq le 22 Fév 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 commentaires
bala maths
bala maths le 27 Fév 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
Arif Hoq le 27 Fév 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];

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by