如何在 MATLAB 中使用哈希表(字典)? [英] How to use Hash Tables (dictionaries) in MATLAB?

查看:41
本文介绍了如何在 MATLAB 中使用哈希表(字典)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按字符串索引访问数据,例如table('one') %returns 1.MATLAB中有这样的数据结构吗?它是如何实施的?

I need to acces data by string index, like table('one') %returns 1. Is there such a data structure in MATLAB? How is it implemented?

推荐答案

在 MATLAB 的最新版本中,有 containers.Map 数据结构.有关更多信息,请参阅 MATLAB 地图容器.这消除了使用 STRUCT 时的一些限制.例如

In recent versions of MATLAB, there's the containers.Map data structure. See MATLAB Map containers for more. This removes some of the restrictions when using STRUCTs. For example

c = containers.Map
c('foo') = 1
c(' not a var name ') = 2
keys(c)
values(c)

这篇关于如何在 MATLAB 中使用哈希表(字典)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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