Filtering the Content of an Array
168 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2013-4-4
编辑:Jan
2013-4-4
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.
采纳的回答
Andrei Bobrov
2013-4-4
编辑:Andrei Bobrov
2013-4-4
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!