Matlab:独特功能的行为 [英] Matlab: Behavior of the unique function

查看:61
本文介绍了Matlab:独特功能的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将代码从R2012a迁移到R2013b.

I'm currently migrating code from R2012a to R2013b.

我注意到unique函数的行为已更改:

I noticed that the unique function behavior has changed:

R2012a

>> size(unique([]))

ans =

     0     0

R2013b

>> size(unique([]))

ans =

     0     1

在我看来,将x删除后,0x0矩阵将变为0x1矩阵,这与我的直觉相反,这实际上是唯一函数所做的事情.有人对此有道理吗?

It seems counter-intuitive to me that a 0x0 matrix would become a 0x1 matrix after removing doublons, which is essentially what the unique function does. Does anybody has a rationale for this?

推荐答案

如果您需要使用旧的行为,则R2013a的行为已更改:

The behaviour has changed with R2013a, if you need the old behaviour use:

size(unique([],'legacy'))

如果两个版本都需要代码,我建议编写一些函数,新版本调用unique(x,'legacy'),旧版本调用unique(x).

If you need code for both versions, I would recommend to write some function which calls unique(x,'legacy') for new versions and unique(x) for old versions.

btw:与unionintersectsetdiffsetxorismember

btw: same issue with union, intersect, setdiff, setxor and ismember

这篇关于Matlab:独特功能的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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