code that would identify the identical rows

1 次查看(过去 30 天)
Hello! I have a text file (.txt) consisting of 'M' rows and 3 columns. I would like to write a code that allows to identify the identical rows (the highlighted rows) and keep only one copy, of each repeated row, within the text file.
As a result, if a row repeats one or more times, I have to recreate the text file (.txt):
- keeping the lines that do not repeat
- bringing back only once the lines that are repeated
For example:
I thank you if anyone can help me!

采纳的回答

Arif Hoq
Arif Hoq 2022-11-18
a=table2array(readtable("file.txt"));
output=unique(a,'rows','stable')
output = 12×3
233.0000 353.0000 1.4912 233.0000 352.0000 1.4912 353.0000 296.0000 64.1228 353.0000 295.0000 64.1228 353.0000 216.0000 64.1228 121.0000 217.0000 162.5439 121.0000 216.0000 162.5439 121.0000 215.0000 162.5439 119.0000 274.0000 184.9123 119.0000 273.0000 184.9123
  3 个评论
Arif Hoq
Arif Hoq 2022-11-18
a=table2array(readtable("file.txt"));
[output,ia,ic]=unique(a,'rows','stable')
output = 12×3
233.0000 353.0000 1.4912 233.0000 352.0000 1.4912 353.0000 296.0000 64.1228 353.0000 295.0000 64.1228 353.0000 216.0000 64.1228 121.0000 217.0000 162.5439 121.0000 216.0000 162.5439 121.0000 215.0000 162.5439 119.0000 274.0000 184.9123 119.0000 273.0000 184.9123
ia = 12×1
1 2 3 4 5 6 8 9 11 12
ic = 15×1
1 2 3 4 5 6 1 7 8 4
index vector ic represents the repetition. Here indexes 1,7,13 are the duplicate rows as well 4,10.
Alberto Acri
Alberto Acri 2022-11-18
Thank you @Arif Hoq!
Is it possible to directly identify the lines that have repetition?
In the case of 'file.txt' have something like this:
coordinates repeatability
2.3300000e+02 3.5300000e+02 1.4912281e+00 2
3.5300000e+02 2.9500000e+02 6.4122807e+01 1

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by