Identify lines that have a repetition (unique function)
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Alberto Acri
il 21 Nov 2022
Modificato: Mathieu NOE
il 21 Nov 2022
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
0 Commenti
Risposta accettata
Mathieu NOE
il 21 Nov 2022
hello
simply this
now the 4th column is your repetition quantity
a=readmatrix("file.txt");
[output,ia,ic]=unique(a,'rows','stable')
B = unique(ic);
Ncount = histc(ic, B); % this willgive the number of occurences of each unique element
out = [output Ncount]
out =
233.0000 353.0000 1.4912 3.0000
233.0000 352.0000 1.4912 1.0000
353.0000 296.0000 64.1228 1.0000
353.0000 295.0000 64.1228 2.0000
353.0000 216.0000 64.1228 1.0000
121.0000 217.0000 162.5439 1.0000
121.0000 216.0000 162.5439 1.0000
121.0000 215.0000 162.5439 1.0000
119.0000 274.0000 184.9123 1.0000
119.0000 273.0000 184.9123 1.0000
369.0000 176.0000 246.0526 1.0000
371.0000 184.0000 246.0526 1.0000
2 Commenti
Mathieu NOE
il 21 Nov 2022
Modificato: Mathieu NOE
il 21 Nov 2022
simply use logical array to select the appropriate lines
a=readmatrix("file.txt");
[output,ia,ic]=unique(a,'rows','stable')
B = unique(ic);
Ncount = histc(ic, B); % this willgive the number of occurences of each unique element
out = [output Ncount] % the 4th column is your repetition quantity
idx = Ncount>=2; % logical array : select only lines for which repeat >= 2
out2 = out(idx,:)
Più risposte (1)
Jan
il 21 Nov 2022
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
0 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Objects in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!