convert a matrix with some zero elments to an array with non-zero elments ?

1 回表示 (過去 30 日間)
som
som 2011 年 12 月 27 日
Hi all
I have a matrix 'A' including some elments equal to zero. i want to make an array 'B' with the non-zero elements of A . for example:
A = [46 0 23;10 73 0; 0 57 13]
B=[46 23 10 73 57 13]
How can I write this program?
Thanks

採用された回答

Image Analyst
Image Analyst 2011 年 12 月 28 日
AT = A'
B = AT(logical(AT))'
A =
46 0 23
10 73 0
0 57 13
AT =
46 10 0
0 73 57
23 0 13
B =
46 23 10 73 57 13

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 12 月 28 日
B = nonzeros(A.');

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by