How can i can convert A matrix to the type i want
1 view (last 30 days)
Show older comments
For example i have a matrix
1 0 1 1 0
1 1 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 1
and i want when i=j that time be zero briefly i want become
0 0 1 1 0
1 0 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 0
how can i write code for it If my matrix name A
0 Comments
Accepted Answer
More Answers (3)
Andrei Bobrov
on 13 Sep 2012
Edited: Andrei Bobrov
on 13 Sep 2012
I=[1 0 1 1 0
1 1 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 1];
I(1:size(I,1)+1:end) = 0;
or
I(eye(size(I))>0) = 0;
1 Comment
Andrei Bobrov
on 13 Sep 2012
if size(I,1) < size(I,2)-2
>> I = ones(4,8)
I =
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
>> I1 = I;
I1(1:size(I,1)+1:end) = 0
I1 =
0 1 1 1 1 0 1 1
1 0 1 1 1 1 0 1
1 1 0 1 1 1 1 0
1 1 1 0 1 1 1 1
>> I2 = I;
I2(eye(size(I))>0) = 0
I2 =
0 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1
1 1 0 1 1 1 1 1
1 1 1 0 1 1 1 1
>>
Sean de Wolski
on 13 Sep 2012
A = [1 0 1 1 0
1 1 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 1 ]
A(1:(size(A,1)+1):end) = 0
0 Comments
Honglei Chen
on 13 Sep 2012
Edited: Honglei Chen
on 13 Sep 2012
Here is another one
A.*~eye(size(A))
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!