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 次查看(过去 30 天)
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
Arif Hoq 2022-2-22
编辑:Arif Hoq 2022-2-22
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 个评论
bala maths
bala maths 2022-2-27
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by