How can i can convert A matrix to the type i want

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

More Answers (3)

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

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

Sign in to comment.

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

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!