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
2012년 9월 13일
편집: Andrei Bobrov
2012년 9월 13일
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
Andrei Bobrov
2012년 9월 13일
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
2012년 9월 13일
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
2012년 9월 13일
편집: Honglei Chen
2012년 9월 13일
Here is another one
A.*~eye(size(A))
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!