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 Center および File ExchangeSpectral Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by