필터 지우기
필터 지우기

Filtering the Content of an Array

조회 수: 121 (최근 30일)
RDG
RDG 2013년 4월 4일
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
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
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개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by