Azzera filtri
Azzera filtri

Filtering the Content of an Array

121 visualizzazioni (ultimi 30 giorni)
RDG
RDG il 4 Apr 2013
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 Commento
Jan
Jan il 4 Apr 2013
Modificato: Jan il 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.

Accedi per commentare.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 4 Apr 2013
Modificato: Andrei Bobrov il 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]),:);

Più risposte (0)

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by