MATLAB: How to exclude rows on the basis of specific entries

excluding rowsfiltermatrices

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?

Best Answer

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, :) = []