container.map 不支持pair matlab
时间: 2024-10-19 18:05:48 浏览: 37
在MATLAB中,`container.Map`数据结构主要用于存储键值对,类似于其他语言中的字典或映射。它并不直接支持存储`pair`类型的元素,因为`pair`并不是MATLAB的内置类型。如果你想要类似的功能,可以创建自定义的`pair`类,并将其作为键值对插入到`container.Map`中。
例如,你可以这样做:
```matlab
classdef MyPair < handle
properties
key
value
end
methods
function obj = MyPair(key, value)
obj.key = key;
obj.value = value;
end
end
end
% 创建一个map并使用自定义的MyPair
myMap = containers.Map();
myMap('key1', MyPair('value1', 'some string')) = 'another pair';
```
然而,由于MATLAB的设计,你通常更倾向于直接使用`structs`(结构体)或者元组(cell array with two elements)来代替`pair`,除非你在编写特定的需求定制的工具箱或者函数时需要这样的灵活性。
阅读全文
相关推荐










