Reputation: 13
I have a matrix 65536x8 with all possible combinations of values - 45 90 135 180 (in 8 columns).
I need to remove all the rows that do not contain all four values (each row cannot be missing any of these values).
This is what I've tried (not working):
>> orient(orient(numel(orient(:,1))) == 45 && 90 && 135 && 180,:)
ans =
Empty matrix: 0-by-8
Is there some efficient way to do this in MATLAB?
Upvotes: 1
Views: 532
Reputation: 45752
This should give you an idea of how to go about it:
A = [1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3];
A(any((A == 1)') & any((A == 2)') & any((A == 3)'),:)
ans =
1 2 3
1 3 2
2 1 3
Or generically using a loop (with only 4 number this should be pretty fast):
rows = true(size(A,1),1); %// Initialization
U = unique(A); %// List of numbers
for n = 1:size(U,1)
rows = rows & any((A == U(n))')';
end
A(rows,:)
Upvotes: 1