selecting particular elements from a cell array

조회 수: 4 (최근 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])

추가 답변 (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