如何从矩阵中删除重复行 [英] How to remove duplicate rows from matrix

查看:25
本文介绍了如何从矩阵中删除重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从矩阵中删除重复的行.我阅读了 如何删除在数组中重复但保持相同的顺序?,但这并不是我想要的.

I want to remove duplicate rows from a matrix. I read How can I remove duplicates in an array but keep the same order?, but this is not exactly what I want.

上面的解决方案从矩阵中删除重复值(单元格)(并返回一个向量),但我需要删除重复的 rows 并返回一个矩阵 —没有重复行的相同矩阵.

The solution above removes duplicate values (cells) from matrix (and returns a vector), but I need to remove duplicate rows and return a matrix — the same matrix without duplicate rows.

例子:

a = [1,2; 3,4; 5,6; 1,2; 7,8]

a =
     1     2
     3     4
     5     6
     1     2
     7     8

%...

ans =
     1     2
     3     4
     5     6
     7     8

顺序无关紧要.

推荐答案

参见 http://www.mathworks.com/help/techdoc/ref/unique.html

b = unique(A, 'rows') 返回 A 的唯一行.

b = unique(A, 'rows') returns the unique rows of A.

这篇关于如何从矩阵中删除重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆