フィルターのクリア

code that would identify the identical rows

1 回表示 (過去 30 日間)
Alberto Acri
Alberto Acri 2022 年 11 月 18 日
コメント済み: Alberto Acri 2022 年 11 月 18 日
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 Center および File ExchangeString についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by