重複したデータを削除する方法
39 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
kanako machii
le 16 Sep 2020
Réponse apportée : Akira Agata
le 18 Sep 2020
重複したデータを削除する方法を教えてください。
具体的には下記のような処理を行いたいと考えています。
A = [600 142 30 75 13; 600 141 30 75 14; 600 142 30 80 14]
Aの5列目の値が他の行の5列目の値と重複している場合に、行数が小さいほうの行を削除したいです。
この場合は1行目と2行目の5列目の値が重複しているので、1行目を削除して、下記のBのような行列を求めたいと考えています。
B=[600 141 30 75 14; 600 142 30 80 14]
uniqueを使えばできそうなのですが、うまくいきません。
宜しくお願い致します。
0 commentaires
Réponse acceptée
Akira Agata
le 18 Sep 2020
findgroups と splitapply を使う方法はいかがでしょうか?
A = [600 142 30 75 13; 600 141 30 75 14; 600 142 30 80 14];
group = findgroups(A(:,4));
B = splitapply(@(x) x(end,:), A, group);
実行結果は以下のとおりです。
>> B
B =
600 141 30 75 14
600 142 30 80 14
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur ワークスペース変数と MAT ファイル 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!