if condition finding same numbers in consecutive rows

Hi guys I have a table with 120 rows and 5 columns. I want an if condition: if the table contains at least two consecutive rows in columns 2,3,4 and 5 which have the same number then write similar table, else do nothing.
Thanks for your help

댓글 수: 1

What exactly is a "table"? On paper, Excel-File, csv-file, matrix in Matlab, a table object? Does "write a similiar table" belong to the problem and if so, what exactly is "similar"?

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

답변 (3개)

Chad Greene
Chad Greene 2015년 3월 13일
You can use diff.
x = [4 5 2 17 17 3 4 2 2 4];
ConsecutiveNumbersStartAt = find(diff(x)==0)
Jim Hokanson
Jim Hokanson 2015년 3월 13일
편집: Jim Hokanson 2015년 3월 13일
sum the differences, but make sure to take the absolute value so that you don't get positives and negatives that cancel out
find(sum(abs(diff(x,1,1)))==0)
Chad Greene
Chad Greene 2015년 3월 13일

0 개 추천

You can use the index outputs of unique with the 'rows' option. That'll give you indices of all the unique rows. Then the redundant rows are what's left over.

댓글 수: 1

AA
AA 2015년 3월 14일
편집: AA 2015년 3월 14일
I tried it but it is not what i wanted. Consider the following numbers
2 7 6 7 4 3 7 8 8
5 7 7 7 4 5 7 8 3
3 3 3 3 3 3 3 3 3
I want to find the last row where all the values across all columns are the same, i.e. lots of 3s. Plz help

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

카테고리

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

질문:

AA
2015년 3월 13일

편집:

AA
2015년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by