フィルターのクリア

Delete the Whole Row and Merge The Next Row in a matrix

2 ビュー (過去 30 日間)
Xiao Tang
Xiao Tang 2012 年 8 月 8 日
I have a Matrix A =
'30' 'X' '@NA'
'15' 'Y' [231.001]
'00' 'Y' [21.110]
'20' 'W' '@NA'
'55' 'X' [9.001]
'10' 'X' [11.211]
>>whos A
Name Size Bytes Class Attributes
aaa 6x3 226 cell
How can I get a new matrix B that delete the whole row of Matrix A if there is anything other than '10','15','20'...'55' in Column 1, or any '@NA' in Column 3 , and MERGE the next qualified row.
Take A for example, Row 1 and 4 should be deleted because there is '@NA' in Column 3. Row 3 should also be deleted because there is '00' in Column 1.
Matrix B should like,
>>B
B =
'15' 'Y' [231.001]
'55' 'X' [9.001]
'10' 'X' [11.211]
B is a 3*3 cell matrix. Any suggestion is welcome!

採用された回答

Matt Kindig
Matt Kindig 2012 年 8 月 8 日
I'm not sure I understand what "merge" you are trying to do. It sounds like you just want to delete rows that satisfy a particular set of column requirements. If so, something like this should work:
An = cellfun(@str2double, A(:,1)); %convert first column to number
tf1 = ismember(An, 10:5:55); %check if A(:,1) is in 10:5:55
tf2 = ~strcmpi(A(:,3), '@NA'); %check that A(:,3) is NOT '@NA'
B = A(tf1 & tf2, :);
  1 件のコメント
Xiao Tang
Xiao Tang 2012 年 8 月 8 日
Logical index is so powerful!

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 8 日
編集済み: Azzi Abdelmalek 2012 年 8 月 8 日
a1=A(:,1);B=A
a1=str2num(cell2mat(A(:,1)))
[i1,j1]=find(mod(a1,5)~=0 | a1<10)
B(i1,:)=[]
ind=cellfun(@(x) isnumeric(x),B(:,3))
result=B(ind,:)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by