Cutting rows and columns from a matrix

4 ビュー (過去 30 日間)
Franco
Franco 2011 年 2 月 10 日
If A = [0,0,0,0;0,0,0,0;0,0,1,1;0,0,1,1], how can i cut out the null comumns and rows to acheive B = [1,1;1,1]

採用された回答

Jos (10584)
Jos (10584) 2011 年 2 月 10 日
See ANY (or ALL). You need a two step approach:
A = [1 0 1 0 ; 1 0 1 0 ; 0 0 0 0]
B = A(any(A,2),:) ; % remove null rows
B = B(:,any(A,1)) % remove null columns

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 5 月 20 日
B = zeros(sum(any(A,2)),sum(any(A)));
B(:)=A(A~=0);

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by