how to delete repeated rows in a table?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an array M below. There are some repeated values in column 1. I would like to write a code that deletes all the rows that have repeated values in column 1. The final answer should be [518640 5.959; 522225 8.988].
This is a sample dataset. My actual data has more than 50,000 rows, and I need to delete all the repeated data. Thanks.
M = [518460 3.322; 518460 -12.984; 518520 3.798; 518520 -10.28; 518580 7.763; 518580 16.851; 518640 5.959; 522225 8.988];
0 commentaires
Réponse acceptée
per isakson
le 24 Sep 2021
Modifié(e) : per isakson
le 27 Sep 2021
Test this
%%
M = [518460 3.322; 518460 -12.984; 518520 3.798; 518520 -10.28; 518580 7.763; 518580 16.851; 518640 5.959; 522225 8.988];
%%
[~,ixu] = unique( M(:,1), 'stable' );
M(ixu,:)
In response to comment
If everything fails, try a for-loop
for jj = 1 : size(M,1)
ixm = find( M(jj,1) == M(:,1) );
if numel(ixm) >= 2
M(ixm,1) = nan;
end
end
M( isnan(M(:,1)), : ) = []
3 commentaires
Plus de réponses (1)
Walter Roberson
le 27 Sep 2021
format long g
M = [518460 3.322; 518460 -12.984; 518520 3.798; 518520 -10.28; 518580 7.763; 518580 16.851; 518640 5.959; 522225 8.988]
[~, ia] = unique(M(:,1), 'stable');
M = M(ia,:)
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!