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.

7 次查看(过去 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