selecting particular elements from a cell array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I have the following cell array
A={
[ 0] [ 0] [ 0] [1.2923] [11.2337]
[ 0] [ 0] [ 0] [1.2923] [11.2337]
'MN1' [ 0] [ 0] [1.2923] [11.2337]
'MN1' [ 0] [ 0] [1.2868] [11.2569]
'MN1' 'AER_KL1' [ 0] [1.3125] [11.5218]
'MN1' 'AER_KL1' [ 0] [1.2906] [11.0013]
'MN1' 'AER_KL1' [ 'B1'] [2.9102] [28.2414]
'MN1' 'AER_KL1' [ 'B1'] [2.9961] [29.4252]
'MN1' 'AER_KL1' [ 'B1'] [3.0740] [29.4386]
'MN1' 'AER_KL1' [ 'B2'] [2.8701] [27.8087]
'MN1' 'AER_KL1' [ 'B2'] [2.9805] [29.6135]
'MN1' 'AER_KL1' [ 'B2'] [2.9793] [29.5466]
'MN1' 'AER_KL1' [ 'B3'] [2.9102] [28.2414]
'MN1' 'AER_KL1' [ 'B3'] [2.9961] [29.4252]
'MN1' 'AER_KL1' [ 'B3'] [3.0740] [29.4386]
'MN1' 'AER_KL2' [ 0] [1.3125] [11.5218]
'MN1' 'AER_KL2' [ 0] [1.2906] [11.0013]
'MN1' 'AER_KL2' [ 'B1'] [2.8701] [27.8087]
'MN1' 'AER_KL2' [ 'B1'] [2.9805] [29.6135]
'MN1' 'AER_KL2' [ 'B1'] [2.9793] [29.5466]
'MN1' 'AER_KL2' [ 'B2'] [2.9102] [28.2414]
'MN1' 'AER_KL2' [ 'B2'] [2.9961] [29.4252]
'MN1' 'AER_KL2' [ 'B2'] [3.0740] [29.4386]
'MN1' 'AER_KL2' [ 'B3'] [2.8701] [27.8087]
'MN1' 'AER_KL2' [ 'B3'] [2.9805] [29.6135]
'MN1' 'AER_KL2' [ 'B3'] [2.9793] [29.5466]
'MN1' [ 0] [ 0] [1.2923] [11.2337]
'MN1' [ 0] [ 0] [1.2868] [11.2569]
'MN1' [ 0] [ 0] [1.3125] [11.5218]
'MN1' [ 0] [ 0] [1.2906] [11.0013]
'MN2' [ 0] [ 0] [1.2923] [11.2337]
'MN2' [ 0] [ 0] [1.2868] [11.2569]
'MN2' 'AER_KL1' [ 0] [1.3125] [11.5218]
'MN2' 'AER_KL1' [ 0] [1.2906] [11.0013]
'MN2' 'AER_KL1' [ 'B1'] [2.9102] [28.2414]
'MN2' 'AER_KL1' [ 'B1'] [2.9961] [29.4252]
'MN2' 'AER_KL1' [ 'B1'] [3.0740] [29.4386]
'MN2' 'AER_KL1' [ 'B2'] [2.8701] [27.8087]
'MN2' 'AER_KL1' [ 'B2'] [2.9805] [29.6135]
'MN2' 'AER_KL1' [ 'B2'] [2.9793] [29.5466]
'MN2' 'AER_KL1' [ 'B3'] [2.9102] [28.2414]
'MN2' 'AER_KL1' [ 'B3'] [2.9961] [29.4252]
'MN2' 'AER_KL1' [ 'B3'] [3.0740] [29.4386]
'MN2' 'AER_KL2' [ 0] [1.3125] [11.5218]
'MN2' 'AER_KL2' [ 0] [1.2906] [11.0013]
'MN2' 'AER_KL2' [ 'B1'] [2.8701] [27.8087]
'MN2' 'AER_KL2' [ 'B1'] [2.9805] [29.6135]
'MN2' 'AER_KL2' [ 'B1'] [2.9793] [29.5466]
'MN2' 'AER_KL2' [ 'B2'] [2.9102] [28.2414]
'MN2' 'AER_KL2' [ 'B2'] [2.9961] [29.4252]
'MN2' 'AER_KL2' [ 'B2'] [3.0740] [29.4386]
'MN2' 'AER_KL2' [ 'B3'] [2.8701] [27.8087]
'MN2' 'AER_KL2' [ 'B3'] [2.9805] [29.6135]
'MN2' 'AER_KL2' [ 'B3'] [2.9793] [29.5466]
[ 0] [ 0] [ 0] [1.2923] [11.2337]
[ 0] [ 0] [ 0] [1.2868] [11.2569]
[ 0] [ 0] [ 0] [1.3125] [11.5218]
[ 0] [ 0] [ 0] [1.2906] [11.0013]
}
I want to select all the numbers from the last 2 columns that correspond to the string variables of column 3 (in the above example 'B1' 'B2' 'B3') AND the the string variables of column 1 (in the above example 'MN1' 'MN2')
So, I want to obtain
A_new={
'MN1' [ 'B1'] [2.9102] [28.2414]
'MN1' [ 'B1'] [2.9961] [29.4252]
'MN1' [ 'B1'] [3.0740] [29.4386]
'MN1' [ 'B2'] [2.8701] [27.8087]
'MN1' [ 'B2'] [2.9805] [29.6135]
'MN1' [ 'B2'] [2.9793] [29.5466]
'MN1' [ 'B3'] [2.9102] [28.2414]
'MN1' [ 'B3'] [2.9961] [29.4252]
'MN1' [ 'B3'] [3.0740] [29.4386]
'MN1' [ 'B1'] [2.8701] [27.8087]
'MN1' [ 'B1'] [2.9805] [29.6135]
'MN1' [ 'B1'] [2.9793] [29.5466]
'MN1' [ 'B2'] [2.9102] [28.2414]
'MN1' [ 'B2'] [2.9961] [29.4252]
'MN1' [ 'B2'] [3.0740] [29.4386]
'MN1' [ 'B3'] [2.8701] [27.8087]
'MN1' [ 'B3'] [2.9805] [29.6135]
'MN1' [ 'B3'] [2.9793] [29.5466]
'MN2' [ 'B1'] [2.8701] [27.8087]
'MN2' [ 'B1'] [2.9805] [29.6135]
'MN2' [ 'B1'] [2.9793] [29.5466]
'MN2' [ 'B2'] [2.9102] [28.2414]
'MN2' [ 'B2'] [2.9961] [29.4252]
'MN2' [ 'B2'] [3.0740] [29.4386]
'MN2' [ 'B3'] [2.8701] [27.8087]
'MN2' [ 'B3'] [2.9805] [29.6135]
'MN2' [ 'B3'] [2.9793] [29.5466] }
I am looking for a code that can identify and select all
the string variables of column 1 AND string variables of column 3 and then find the numbers that correspond
to these string variables
Is there a way of doing that?
thanks
1 commentaire
Réponse acceptée
Matt Fig
le 25 Sep 2012
Modifié(e) : Matt Fig
le 25 Sep 2012
idx = all(cellfun(@(x) ~isequal(x,0),A(:,[1 3])),2)
R = A(idx,[1 3 4 5])
1 commentaire
Andrei Bobrov
le 25 Sep 2012
A(all(cellfun(@ischar,A(:,[2,3])),2),[1,3:end])
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!