selecting particular elements from a cell array

7 ビュー (過去 30 日間)
Sabbas
Sabbas 2012 年 9 月 25 日
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 件のコメント
Daniel Shub
Daniel Shub 2012 年 9 月 25 日
There are a number of ways of doing this. What have you tried so far?

サインインしてコメントする。

採用された回答

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])
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 9 月 25 日
A(all(cellfun(@ischar,A(:,[2,3])),2),[1,3:end])

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by