In a 6x6 square matrix A, how to select elements in i-th row with A(i,j) ruled out
3 views (last 30 days)
Show older comments
n=12;
A=zeros(n,n);
B=zeros(n,n);
if A(i,(i-1):(i+1):n)==0
B(i,i)=1;
end
2 Comments
Accepted Answer
KSSV
on 24 May 2022
A = [0 0 -1 1
1 1 0 0
0 0 1 0
1 -1 0 1] ;
B = zeros(size(A)) ;
for i = 1:4
if A(i,i) == 1 % if disagonal element = 1
temp = A(i,:) ; % get the ith row
temp(i) = [] ; % remove the diagonal element
if ~any(temp) % check whether all are zeros
B(i,i) = 1 ; % Make B(i,i) = 1
end
end
end
B
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!