Identify lines that have a repetition (unique function)
Show older comments
From the attached file, I applied this code to eliminate repeated rows:
a=table2array(readtable("file.txt"));
[output,ia,ic]=unique(a,'rows','stable')
repetition = ic;
Is it possible to directly identify the lines that have repetition?
For '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
Accepted Answer
More Answers (1)
data = [ 2.3300000e+02 3.5300000e+02 1.4912281e+00
2.3300000e+02 3.5200000e+02 1.4912281e+00
3.5300000e+02 2.9600000e+02 6.4122807e+01
3.5300000e+02 2.9500000e+02 6.4122807e+01
3.5300000e+02 2.1600000e+02 6.4122807e+01
1.2100000e+02 2.1700000e+02 1.6254386e+02
2.3300000e+02 3.5300000e+02 1.4912281e+00
1.2100000e+02 2.1600000e+02 1.6254386e+02
1.2100000e+02 2.1500000e+02 1.6254386e+02
3.5300000e+02 2.9500000e+02 6.4122807e+01
1.1900000e+02 2.7400000e+02 1.8491228e+02
1.1900000e+02 2.7300000e+02 1.8491228e+02
2.3300000e+02 3.5300000e+02 1.4912281e+00
3.6900000e+02 1.7600000e+02 2.4605263e+02
3.7100000e+02 1.8400000e+02 2.4605263e+02];
repeated = isMultipleRow(data)
function T = isMultipleRow(A)
nA = height(A);
T = false(nA, 1);
[S, idx] = sortrows(A);
m = [false; ~any(diff(S, 1, 1), 2)];
if any(m) % Any repeated elements found:
ini = strfind(m.', [false, true]);
m(ini) = true; % Mark 1st occurence in addition
T(idx) = m; % Restore original order
end
end
Categories
Find more on MATLAB 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!