I have a nxn matrix(A) which has many zero rows and zero columns.. I removed the zero rows and columns using the command below such that Anew is now (n-m) x (n-m). After some computations on Anew matrix, I need to get Anew matrix back to nxn matrix.

조회 수: 8 (최근 30일)
I am removing the zero rows and zero columns from my matrix A using the command:
Anew=A(any(A,2),any(A,1)) ;where A(nxn) and Anew((n-m)x(n-m)) where there are m zero rows/columns
After some computation on Anew, I need to add the zero rows and columns back to their original position so that Anew now becomes nxn..
How to do it? Please help

채택된 답변

James Tursa
James Tursa 2018년 1월 25일
temp = A;
temp(any(A,2),any(A,1)) = Anew;
Anew = temp;
  댓글 수: 4
SanthoshKumar C
SanthoshKumar C 2018년 1월 26일
Ur posted code will give Anew matrix of size nxn. But what I need is lil different.
Ex:
A=[1 0 2 0 3; 0 0 0 0 0; 4 0 5 0 6; 0 0 0 0 0; 7 0 8 0 9];
After the step,
Anew=A(any(A,2),any(A,1)) ;
Anew =
1 2 3
4 5 6
7 8 9
Now I am doing some computation on Anew such that modified Anew will be as follows:
Anew = Anew+5
Anew =
6 7 8
9 10 11
12 13 14
Last step: (Need to do this now) . Insert the zero rows and columns back to the original position in Anew such that Anew looks like this
Anew =
6 0 7 0 8
0 0 0 0 0
9 0 10 0 11
0 0 0 0 0
12 0 13 0 14
SanthoshKumar C
SanthoshKumar C 2018년 1월 26일
Since I am working on matrix inverse of a (300+)x(300+) matrix which can have a more number of zero rows and columns (ill-conditioned matrix ofcourse).. Need robust way to do this

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

SanthoshKumar C
SanthoshKumar C 2018년 1월 26일
Thanks James Tursa.. I overlooked your answer.. Its working

카테고리

Help CenterFile Exchange에서 Spectral Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by