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

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

问题描述

在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天全站免登陆