필터 지우기
필터 지우기

comparing two columns of a table in MATLAB

조회 수: 33 (최근 30일)
Annick
Annick 2020년 3월 27일
댓글: Annick 2020년 3월 27일
Hello!
I want to compare the second column with the 3rd column to find out if there is any row having the same values in both columns.
Let's say, for example, 1st ,3rd and 4th rows have the same values in both the two columns. I would like to add another column to the table which shows me if the rows are compared with eachother.
Currently I have wrote this loop, but it writes 0 eventhough the columns are the same
i=1:height(Table1);
if(Table1.Interval1 == Table1.ActivityCode1)
Comparison(i)= 1;
else
Comparison(i)= 0;
end
Comparison = (Comparison)';
Could you please help me?

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 3월 27일
편집: Geoff Hayes 2020년 3월 27일
Annick - how about you remove the loop and just do
Comparison = Table1.Interval1 == Table1.ActivityCode1;
Wouldn't Comparison be an array of ones and zeros where a one indicates that the two elements (in whatever row) are equal, and a zero indicating that the two elements aren't zero?
  댓글 수: 1
Annick
Annick 2020년 3월 27일
Thank you so much for your quick answer :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by