Matlab:ismember中的错误?

时间:2013-12-10 12:35:41

标签: matlab

我在某处定义了枚举:

classdef MyError

  enumeration

    Error0
    Error1
    Error2

  end

end

然后,我正在尝试用不同版本的Matlab简单调用ismember。

R2012a:

>> enums = enumeration('MyError');
>> ismember(MyError.Error0,enums)

ans =

     1

R2013b:

>> enums = enumeration('MyError');
>> ismember(MyError.Error0,enums)
Undefined function 'sort' for input arguments of type 'MyError'.
Error in ismember>ismemberClassTypes (line 711)
    sort(ab(1));
Error in ismember>ismemberR2012a (line 490)
            lia = ismemberClassTypes(a,b);
Error in ismember (line 57)
    [varargout{1:max(1,nargout)}] = ismemberR2012a(A,B); 

我正在查看发出错误的代码,我无法理解调用'sort'的目的是什么,因为它的输入是一个标量值而输出没有存储。鉴于调用枚举值的成员是相当常见的任务,我很惊讶地看到这样的回归。

任何解决方法的想法?

2 个答案:

答案 0 :(得分:0)

我无法在本地对此进行测试,但您可能需要检查是否可以使用略微修改的类定义:

classdef MyError < uint32

  enumeration

    Error0 (0)
    Error1 (1) 
    Error2 (2)

  end

end

对任何数字类型进行子类化应该可以获得sort - 方法。 这仍然不是一个真正的修复或解释,但可能是最好的解决方法。

答案 1 :(得分:0)

不幸的是,这似乎是一个功能,而不是一个错误。

在matlab的“旧”版本中,帮助文件指出:

In a future release, the behavior of ismember will change including:
  - occurrence of indices in LOCB will switch from highest to lowest
  - tighter restrictions on combinations of classes

In order to see what impact those changes will have on your code, use:

   [LIA,LOCB] = ismember(A,B,'R2012a')
   [LIA,LOCB] = ismember(A,B,'rows','R2012a')

If the changes in behavior adversely affect your code, you may preserve
the current behavior with:

   [LIA,LOCB] = ismember(A,B,'legacy')
   [LIA,LOCB] = ismember(A,B,'rows','legacy')

如果我尝试启用R2012a标志,我确实会收到您提到的错误。因此,我认为给出的建议对你有用。包含legacy标志,可能会有效。

相关问题