矩阵上的垃圾,索引和唯一性(如何保持矩阵格式) [英] junk, index and unique on a matrix (how to keep matrix format)

查看:17
本文介绍了矩阵上的垃圾,索引和唯一性(如何保持矩阵格式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 8x8 矩阵上使用此方法:

Using this method on a 8x8 matrix:

>> [junk,index] = unique(data,'first');        %# Capture the index, ignore junk
>> data(sort(index))                           %# Index data with the sorted index

以 64x1 格式(如果未找到重复)或 nx1(如果找到一些重复)输出格式.

Outputs the format in 64x1 format (if no repeats are found) or nx1 if some repeats are found.

我的问题是如何在没有排序的情况下保持矩阵格式?

My question is how do I keep the matrix format without the sorting?

我需要它来检查唯一(行)是否存在重复的非唯一单元格.并删除重复的行但保留格式(不要排列/排序).

i need it to check unique(rows) for duplicates not unique cells. And to delete the duplicate rows but keep the format (dont arrange/sort).

推荐答案

如果你想要唯一的行,同时保持原始顺序,试试这个:

If you want unique rows, while keeping original order, try this:

[M,ind] = unique(data, 'rows', 'first');
[~,ind] = sort(ind);
M = M(ind,:);

例子:

>> data = randi(2,[8 3]);
data =
     1     2     1
     1     2     1
     1     1     2
     2     2     2
     1     1     1
     2     2     2
     2     2     2
     2     1     1
>> M
M =
     1     2     1
     1     1     2
     2     2     2
     1     1     1
     2     1     1

这篇关于矩阵上的垃圾,索引和唯一性(如何保持矩阵格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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