フィルターのクリア

How can I delete the rows of a matrix in matlab under a given condition

11 ビュー (過去 30 日間)
Sky Scrapper
Sky Scrapper 2018 年 11 月 14 日
編集済み: madhan ravi 2018 年 11 月 23 日
Hello everybody,
I have a matrix which has 10118 rows and 14 columns. I would like to delete the number of rows having values greater than 100. How can I do this?
Thanks in advance!

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 14 日
編集済み: madhan ravi 2018 年 11 月 23 日
EDITED
%Numbers greater than 100
idx = matrix > 100;
matrix ( ~ ( sum ( idx , 2) == 0 ) , : ) = []
%__________________________
%Numbers lesser than 100
idx = matrix < 100;
matrix ( sum ( idx , 2 ) ~= 0 , : ) = []
  21 件のコメント
Stephen23
Stephen23 2018 年 11 月 23 日
編集済み: Stephen23 2018 年 11 月 23 日
This code, although convoluted, will remove rows with any value greater than 100:
idx = matrix < 100;
matrix ( ~ ( sum ( idx , 2) == 0 ) , : ) = []
But what is this going to do?:
idx = matrix < 100;
matrix ( sum ( idx , 2 ) == size ( matrix , 2 ) , : ) = []
madhan ravi
madhan ravi 2018 年 11 月 23 日
編集済み: madhan ravi 2018 年 11 月 23 日
@Skyscraper: yes because if any of the numbers in a matrix is less than 100 the whole row is removed, the matrix which you gave contains numbers less than 100 in each row.

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

その他の回答 (1 件)

Stephen23
Stephen23 2018 年 11 月 23 日
編集済み: Stephen23 2018 年 11 月 23 日
@Sky Scrapper: the standard MATLAB practice is to use any:
>> A = [110,0,10,70,15;100,30,50,20,9;50,-150,95,65,7]
A =
110 0 10 70 15
100 30 50 20 9
50 -150 95 65 7
>> B = A(~any(abs(A)>100,2),:) % create a new array B,
B =
100 30 50 20 9
>> A(any(abs(A)>100,2),:) = [] % or delete rows from A.
A =
100 30 50 20 9
  1 件のコメント
Sky Scrapper
Sky Scrapper 2018 年 11 月 23 日
Yes, it's working properly. Thank you very much for your help!

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

カテゴリ

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