フィルターのクリア

How to delete specific rows in a matrix

4 ビュー (過去 30 日間)
Maryam Hamrahi
Maryam Hamrahi 2017 年 4 月 18 日
コメント済み: Maryam Hamrahi 2017 年 4 月 18 日
Hi everybody,
I have a very huge matrix, and I need to deleted rows when some of column numbers are equal to zero.
Here is a simple example.
A=[ a1 a2 a3 a4 a5 a6 a7 a8
b1 b2 b3 b4 b5 0 0 0
c1 c2 c3 c4 c5 0 0 0
d1 d2 d3 d4 d5 d6 d7 d8
.
.
.
.
.
.
.
z1 z2 z3 z4 z5 0 0 0]
how could I delete rows when the last three columns are zero?
Thank you very much.
  1 件のコメント
Maryam Hamrahi
Maryam Hamrahi 2017 年 4 月 18 日
I used this code to solve a simple example:
A= [1 2 3 4 5 0 0
1 2 4 7 8 0 0
2 3 5 4 3 5 7];
TF = A(:,6:7)==0
% remove
A(TF,:) = []
why I get this error:
Error in Untitled (line 6)
A(TF,:) = []

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

採用された回答

Stephen23
Stephen23 2017 年 4 月 18 日
編集済み: Stephen23 2017 年 4 月 18 日
You need to use all or any:
>> A = [1,2,3,4,5,0,0; 1,2,4,7,8,0,0; 2,3,5,4,3,5,7]
A =
1 2 3 4 5 0 0
1 2 4 7 8 0 0
2 3 5 4 3 5 7
>> B = A(any(A(:,6:7),2),:)
B =
2 3 5 4 3 5 7
  1 件のコメント
Maryam Hamrahi
Maryam Hamrahi 2017 年 4 月 18 日
Thank you Stephen Cobeldick.
It was very nice of you.

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

その他の回答 (0 件)

カテゴリ

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