I have the folloing table:
Tool1 Mek Ar 10.0 40.5
Tool1 Lahi BM2 13.0 89.4
Tool1 Ar Ar 34.0 67.8
Tool1 Puni Raj 41.0 89.9
Tool1 Jak Ar 20.0 78.3
Tool1 Lahi Lahi 12.0 99.0
Tool1 N2 BM2 14.0 89.0
Tool1 Ar Mek 25.0 95.7
Tool1 Puni Puni 17.0 90.6
Tool1 Raj Jak 20.0 100.0
uncommon list:
Ar
BM2
N2
I want to remove a particular row if:
1. If the name in second column & third column (of any row) is equal (I mean same)
2. If the name in third column (of any row) belongs to uncommon list
Many thanks in advance.

댓글 수: 1

Image Analyst
Image Analyst 2015년 12월 26일
Is it a table (hopefully), or a cell array? If it's a cell array, you should really use a table instead because they're easier to deal with, faster, and take up a lot less memory. Let me know if you don't even know the difference between a table (which was introduced in R2013b) and a cell array.

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 12월 25일
편집: Azzi Abdelmalek 2015년 12월 25일

0 개 추천

If A is your cell array and b the uncomon list
A={'Tool1' 'Mek' 'Ar' 10.0 40.5
'Tool1' 'Lahi' 'BM2' 13.0 89.4
'Tool1' 'Ar' 'Ar' 34.0 67.8
'Tool1' 'Puni' 'Raj' 41.0 89.9
'Tool1' 'Jak' 'Ar' 20.0 78.3
'Tool1' 'Lahi' 'Lahi' 12.0 99.0
'Tool1' 'N2' 'BM2' 14.0 89.0
'Tool1' 'Ar' 'Mek' 25.0 95.7
'Tool1' 'Puni' 'Puni' 17.0 90.6
'Tool1' 'Raj' 'Jak' 20.0 100.0 }
b={'Ar';'BM2';'N2'}
ii=cellfun(@(x,y) isequal(x,y) & any(ismember(b,y)),A(:,2),A(:,3))
A(ii,:)=[]

댓글 수: 4

Kanakaiah Jakkula
Kanakaiah Jakkula 2015년 12월 25일
편집: Kanakaiah Jakkula 2015년 12월 25일
Sir, I getting the answer as below as per your code:
Tool1 Mek Ar
Tool1 Lahi BM2
Tool1 Puni Raj
Tool1 Jak Ar
Tool1 Lahi Lahi
Tool1 N2 BM2
Tool1 Ar Mek
Tool1 Puni Puni
Tool1 Raj Jak
But in rows 1,2,3,5,&7 of third column belongs to uncommon list (so the rows 1,2,3,5,7 should be removed), and in rows 6 & 9 the names in columns 2 & 3 are equal (same), agani these rows 6&9 should be removed. Therefore, finally I should get the below answer,
Tool1 Puni Raj 41.0 89.9
Tool1 Ar Mek 25.0 95.7
Tool1 Raj Jak 20.0 100.0
Azzi Abdelmalek
Azzi Abdelmalek 2015년 12월 26일
You have to clarify your question (condition 1 & condition 2) or (condition 1 & condition 2)
Azzi Abdelmalek
Azzi Abdelmalek 2015년 12월 26일
편집: Azzi Abdelmalek 2015년 12월 26일
In your last comment, we understand that the condition is (condition 1 | condition 2). The solution will be
ii=cellfun(@(x,y) isequal(x,y) | any(ismember(b,y)),A(:,2),A(:,3))
A(ii,:)=[]
Kanakaiah Jakkula
Kanakaiah Jakkula 2015년 12월 26일
Sir, it works, and this is I want. But, I am sorry to say that I did not quite understand about this code. One thing I want to ask, how does it working for condition 2 that if any of the row in column 3 belongs to uncommon list, to be removed. If I want to do this for any other column, then where should I modify this code.
Many thanks so far for your kind support.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by