问题描述
我目前正在将代码从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:与union
,intersect
,setdiff
,setxor
和ismember
btw: same issue with union
, intersect
, setdiff
, setxor
and ismember
这篇关于Matlab:独特功能的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!