matlab数据去冗余,取出a中那个不重复元素构成的向量

function [b,ndx,pos] = unique(a,flag1,flag2)
%  UNIQUE Set unique.
%   B = UNIQUE(A) for the array A returns the same values as in A but
%   with no repetitions. B will also be sorted. A can be a cell array of
%   strings.
%
%   UNIQUE(A,'rows') for the matrix A returns the unique rows of A.
%
%   [B,I,J] = UNIQUE(...) also returns index vectors I and J such
%   that B = A(I) and A = B(J) (or B = A(I,:) and A = B(J,:)).
%
%   [B,I,J] = UNIQUE(...,'first') returns the vector I to index the
%   first occurrence of each unique value in A.  UNIQUE(...,'last'),
%   the default, returns the vector I to index the last occurrence.


取集合的单值元素

函数
格式  b = unique (a)         %取集合a的不重复元素构成的向量
b = unique (A,'rows')   % 返回A中不同行向量组成的矩阵
[b,i,j] = unique (…)     %i、j体现b中元素在原向量(矩阵)中的位置

>>  A=[1 1 2 2 4 4 6  4  6]
A =
     1     1     2     2     4     4     6     4     6
>> B=unique(A)
B =

     1     2     4     6


>> A=[1 1 2 2 4 4 6  4  6]
A =
     1     1     2     2     4     4     6     4     6
>> [B,i,j]=unique(A)
B =
     1     2     4     6
i =
     2     4     8     9
j =
   1     1     2     2     3     3     4     3     4


>> A=[1 2 2 4;1 1 4 6;1 1 4 6]
A =
     1     2     2     4
     1     1     4     6
     1     1     4     6
>> [B,i,j]=unique(A,'rows') %A中A(1,:)与A(2,:)不同,所以返回这2个向量组成的矩阵。A(2,:)和A(3,:)相同,
B =
     1     1     4     6
     1     2     2     4
i =
     3
     1
j =
     2
     1

     1

B=A(i,:);

A=B(j,:);

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值