How to exclude rows on the basis of specific entries?

36 ビュー (過去 30 日間)
Ammy
Ammy 2018 年 2 月 6 日
コメント済み: Ammy 2018 年 2 月 9 日
I have 260 rows and 16 columns with entries belong to {1,2,3,4}, I want to exclude those rows in which first four entries of each row is 4 , or in general how can I exclude rows on the basis of entries?

採用された回答

Guillaume
Guillaume 2018 年 2 月 6 日
It's not clear what you mean by repeat.
If you mean you want to delete rows whose first four columns contain more than one 4:
A = [4 4 1 2; 4 4 4 4;1 4 2 4;4 2 3 2]
todelete = sum(A(:, 1:4) == 4, 2) > 1;
A(todelete, :) = []
If you mean you want to delete rows whose first four columns contain two more more consecutive 4, then it's a lot more complicated. One possible way
A = [4 4 1 2; 4 4 4 4;1 4 2 4;4 2 3 2]
todelete = cellfun(@(row) ~isempty(strfind(row, [1 1])), num2cell(A(:, 1:4) == 4, 2));
A(todelete, :) = []
  9 件のコメント
Ammy
Ammy 2018 年 2 月 9 日
Sorry , its work. Thank you for the help.
Ammy
Ammy 2018 年 2 月 9 日
A =
1 2 3 4 0 1 2 3
0 1 2 3 1 2 3 4
1 2 3 4 1 1 1 1
1 2 4 5 3 2 1 2
How can I separate those rows having first four entries are in the order 1 2 3 4 e.g in the above example I want to separate first and third row .

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

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2018 年 2 月 6 日
Here is a flexible example:
% data
X = [4 4] ; % rows starting with this should be discarded
A = [1 4 1 4 ; 4 4 2 2 ; 4 2 4 0 ; 4 4 4 4 ; 2 4 4 2] ; % rows 2 and 4 should be discarded
% engine
tf = ismember(A(:,1:numel(X)), X, 'rows')
A(tf) = [] ; % remove

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by