在matlab中删除具有相同第一列值的行
我在 Matlab 中有一个大小为 10000 X 3 的单元矩阵,我想删除第一列中具有相同值的行。
也就是说,如果第 i 行和第 j 行在第一列中具有相同的值,我想删除这两行。
我还应该说,第一列中可能有两行以上具有相同的值,在这种情况下,我想删除所有这些行。
我该怎么做?
谢谢!
I have a cell matrix of size 10000 X 3 in Matlab and I would like to remove rows with the same value in the first column.
That is, if row i and row j have the same value in the first column, I'd like to delete both rows.
I should also say that there can be more than two rows with the same value in the first column and in that case, I'd like to delete all these rows.
How do I do it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用函数
histc
, < a href="http://www.mathworks.com/help/techdoc/ref/unique.html" rel="nofollow">唯一
和逻辑索引来实现你想要的。这是一个小例子。仅选择具有非重复元素的行。既然您说您有一个单元矩阵,只需使用
cell2mat
在执行此操作之前。You can use the functions
histc
,unique
and logical indexing to achieve what you want. Here's a small example.Only the row with the non-repeated element is selected. Since you said that you have a cell matrix, simply covert it to a matrix using
cell2mat
before doing this.