if condition finding same numbers in consecutive rows
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 13 Mär. 2015
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"?
Antworten (3)
Chad Greene
am 13 Mär. 2015
You can use diff.
x = [4 5 2 17 17 3 4 2 2 4];
ConsecutiveNumbersStartAt = find(diff(x)==0)
Jim Hokanson
am 13 Mär. 2015
Bearbeitet: Jim Hokanson
am 13 Mär. 2015
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)
0 Kommentare
Chad Greene
am 13 Mär. 2015
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 Kommentar
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!