Delete only consecutive repeated string entries from a dataset in matlab
Show older comments
hi!
I am relatively new to matlab. I have a dataset having three columns, time, pitch and notation. for eg
time pitch notation
2.5725 329.63 G
2.5800 329.63 G
2.5900 311.13 M
2.5900 311.13 M
2.6000 570.40 P
I want to remove duplicates occurring consecutively in the file such that the order remains the same. so the output will be:
time pitch notation
2.5725 329.63 G
2.5900 311.13 M
2.6000 570.40 P
I am currently using matlab 7.9.0 so the first of unique command id not supported. Can anyone tell me how to go about it further.
[EDITED, table formatted, Jan]
5 Comments
Please follow the "? Help" link to learn how to format messages in the forum.
The description of the input is not clear. If you use valid Matlab syntax to define the value, it gets clear, if "2.5725" is a string or a double, if the dataset is a cell matrix or a struct, which contains the data as column vectors. Should blank lines appear in the output, or do you want these lines to be deleted? Do only the 2nd and 3rd column matter for the recognition of equal rows? Are you taling about neighboring rows only or does the order of rows not matter?
Cedric
on 29 Aug 2013
Is the 'notation' field/column always one character long?
avantika
on 29 Aug 2013
I still do not understand the empty lines and the type of the input is not explained here. Is this a text file, a cell containing strings, or or is pitch a field of a struct, which contains a double vector?
What should happen for:
2.5725 329.63 GM
2.5800 329.63 GM
2.5725 329.63 GM
2.5800 329.63 GM
So does "consecutively" mean the position in the array or should a line vanish, if there is any equal set of values before, even if other lines appear in between?
I assume that the solution is very easy, if you define the wanted procedure and the class of the input exactly.
Accepted Answer
More Answers (1)
Simon
on 29 Aug 2013
Hi!
I don't understand why the second entry is removed. Is a "duplicate" defined if all three columns match or only the second and third?
Does the unique command in 7.9 support rows? Like
b = unique(A, 'rows')
Does your data set consist of single lines for each entry? You could try to put each data set as a string in a cell array and use unique of the cell array.
Categories
Find more on Managing Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!