selecting particular elements from a cell array

3 次查看(过去 30 天)
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

采纳的回答

Matt Fig
Matt Fig 2012-9-25
编辑:Matt Fig 2012-9-25
idx = all(cellfun(@(x) ~isequal(x,0),A(:,[1 3])),2)
R = A(idx,[1 3 4 5])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by