フィルターのクリア

How to delete rows from the bottom of matrix

3 ビュー (過去 30 日間)
Betina Isbak
Betina Isbak 2013 年 9 月 16 日
Hi everyone,
I have A = [1 2 3 4 5; 1 0 0 0 0; 1 2 3 4 5; 1 2 3 4 5; 1 0 0 0 0; 1 0 0 0 0 ]
I want to delete the rows that contain 0 in the bottom. Then I can’t use
condition=A == 0;
A(condition,:)=[];
as it will delete row 2 as well. I just want to remove the rows in the bottom until the rows start to contain numbers. The number of rows in the bottom can change.
Any ideas? Thanks!!
  1 件のコメント
Jan
Jan 2013 年 9 月 16 日
編集済み: Jan 2013 年 9 月 16 日
The description is not clear. Does they mean, that you want to delete the last two rows only? All rows contain numbers, because 0 is a number also. And no row contains zeros only. Please edit the question and improve the description.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 9 月 16 日
out = A(flipud(cumsum(flipud(all(A,2)))>0),:);
  1 件のコメント
Betina Isbak
Betina Isbak 2013 年 9 月 16 日
Thank you Andrei, it works perfect!

サインインしてコメントする。

その他の回答 (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