MATLAB Answers

How to compare two columns in a table and delete that row having same values in that columns?

조회 수: 7(최근 30일)
Sanwal Zeb
Sanwal Zeb 12 Apr 2021 21:44
댓글: dpb 18 Apr 2021 20:47
column1 column 2 columns3
ball bat gloves
bat gloves bat
ball gloves ball
Mow if I compare column1 and column3, I want to remove the rows having same values in that row of the columns

답변(2개)

dpb
dpb 12 Apr 2021 21:57
c=string({'column1' 'column 2' 'columns3'
'ball' 'bat' 'gloves'
'bat' 'gloves' 'bat'
'ball' 'gloves' 'ball'});
c=c(c(:,1)~=c(:,3),:);
returns
>> c
c =
2×3 string array
"column1" "column 2" "columns3"
"ball" "bat" "gloves"
>>
I kept the header row to have something else in the array as a result...

Sanwal Zeb
Sanwal Zeb 18 Apr 2021 18:28
Hi, I want to do this in tables not in strings.
  댓글 수: 1
dpb
dpb 18 Apr 2021 20:47
Well, we'll have to see what you really have to write actual syntax...we can't see your workspace from here...

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

Community Treasure Hunt

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

Start Hunting!

Translated by