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

 채택된 답변

추가 답변 (3개)

Andrei Bobrov
Andrei Bobrov 2012년 9월 13일
편집: Andrei Bobrov 2012년 9월 13일

2 개 추천

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

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
Sean de Wolski 2012년 9월 13일

1 개 추천

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
Honglei Chen
Honglei Chen 2012년 9월 13일
편집: Honglei Chen 2012년 9월 13일

1 개 추천

Here is another one
A.*~eye(size(A))

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2012년 9월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by