Filtering the Content of an Array
169 views (last 30 days)
Show older comments
Suppose I have an array, arr with contents as follow:
A B C D
1 3 2 3
1 4 1 2
1 3 3 5
2 6 1 4
2 5 4 3
2 6 3 3
2 4 3 2
2 5 4 2
4 2 4 4
4 1 4 6
4 6 5 3
71 1 4 4
71 3 2 3
71 3 1 1
71 4 1 3
71 3 2 3
71 5 2 2
How can I filter the results to achieve the following:
A B C D
2 6 1 4
2 5 4 3
2 6 3 3
2 4 3 2
2 5 4 2
71 1 4 4
71 3 2 3
71 3 1 1
71 4 1 3
71 3 2 3
71 5 2 2
1 Comment
Jan
on 4 Apr 2013
Edited: Jan
on 4 Apr 2013
There is an infinite number of possible solutions. Although we can try to use our crystal balls, this could be a source of missunderstandings. Please explain the wanted procedure with any details.
Please note, that the type and size of the "arrays" is not clear: Does "A,B,C,D" belong to the array, such that it must be a cell arrays, because numerical arrays cannot contain numbers and characters? Or ist this any kind of header, and the actual data are 4 vectors or 1 matrix?
The less we have to guess, the easier and more likely helpful is the answer.
Accepted Answer
Andrei Bobrov
on 4 Apr 2013
Edited: Andrei Bobrov
on 4 Apr 2013
ABCD = [1 3 2 3
1 4 1 2
1 3 3 5
2 6 1 4
2 5 4 3
2 6 3 3
2 4 3 2
2 5 4 2
4 2 4 4
4 1 4 6
4 6 5 3
71 1 4 4
71 3 2 3
71 3 1 1
71 4 1 3
71 3 2 3
71 5 2 2];
out = ABCD(ABCD(:,1) == 2 | ABCD(:,1) == 71,:);
or
out = ABCD(ismember(ABCD(:,1),[2 ,71]),:);
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!