Delete Rows of an Array where a given column is less (or greater) than a given value

91 ビュー (過去 30 日間)
Hello!
With an array like this:
A= 4 2 3
1 6 5
1 2 9
5 2 2
1 2 6
I would like to have an array with (for example) column 3 less than 5. I know that sortrows(A,3) can get the rows in order, but what is the (logical?) test to eliminate these rows?
Thanks!
Doug
  1 件のコメント
Douglas Anderson
Douglas Anderson 2015 年 5 月 22 日
Just to be clear! I mean that the VALUE of column 3 is less than 5!

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

採用された回答

Star Strider
Star Strider 2015 年 5 月 22 日
編集済み: Star Strider 2015 年 5 月 22 日
To eliminate the rows with the value of column 3 less than 5, keep those with the value of column 3 greater than or equal to 5:
A = A(A(:,3) >= 5, :)
similarly:
A(A(:,3) < 5, :) = []
will both produce:
A =
1 6 5
1 2 9
1 2 6
Is this what you want to do?
  4 件のコメント
WENDY ZHANG
WENDY ZHANG 2019 年 1 月 8 日
Really helpful!
William McMillan
William McMillan 2019 年 2 月 22 日
編集済み: William McMillan 2019 年 2 月 22 日
I have a 39801x7 array and i would like to keep any row that has a value greater than 5 or value less than -5. How would I do this?

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by