필터 지우기
필터 지우기

Please help me in coding of multidimensional array

조회 수: 3 (최근 30일)
Nilesh Mate
Nilesh Mate 2017년 10월 27일
답변: Andrei Bobrov 2017년 10월 27일
Hi,
I will like to run the following code,
A =
[1 2 3 4 5 6;
4 0 6 -1 2 4;
-2 4 0 -10 11 56;
0 -10 -25 28 45 52;
-8 -6 0 -15 0 28;
-7 -28 -45 0 -75 52;]
In the above matrix, if the diagonal term is zero then that row and column should be deleted and it gives the final matrix as
A =
[1 4 6;
0 28 52;
-7 0 52;]

채택된 답변

KSSV
KSSV 2017년 10월 27일
A =[1 2 3 4 5 6;
4 0 6 -1 2 4;
-2 4 0 -10 11 56;
0 -10 -25 28 45 52;
-8 -6 0 -15 0 28;
-7 -28 -45 0 -75 52;]
d = diag(A) ;
[i,j] = find(d==0) ;
A(i,:) = [] ;A(:,i) = [] ;

추가 답변 (2개)

Roger Stafford
Roger Stafford 2017년 10월 27일
A = A([1,4,6],[1,4,6]);

Andrei Bobrov
Andrei Bobrov 2017년 10월 27일
ii = find(diag(A))
out = A(ii,ii)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by