【发布时间】:2010-12-13 15:35:43
【问题描述】:
是否可以重载subsref 和subsasgn 以允许索引值使用非整数类型?
h = Hash; #% a custom hash class to manage my data
h(100) = 'data'; #% integer is fine, if index > 0
h{'string'} #% but this fails
??? Cell contents reference from a
non-cell array object.
有人能破解它吗?
确切的解决方案:
containers.Map 中有几个烦恼,可以通过自定义类继承它来解决:
classdef Hash < containers.Map
# fun
end
在这样的类中,可以实现各种类型的键(不仅仅是一个!!)和方便用户操作的方法。也可以重新定义subsref 和subsasgn 以使用花括号和多个索引。不错!
【问题讨论】:
-
还有一个内置的解决方案:'Containers.Map'。看看stackoverflow.com/questions/3591942/hash-tables-in-matlab
标签: matlab hash indexing operator-overloading