Matlab中的元组结构等价 [英] Tuple structure equivalent in Matlab

查看:460
本文介绍了Matlab中的元组结构等价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Haskell中,有一个称为元组的结构,它允许两个元素配对在一起(即:(1,2),('A','B')等)

我想知道在Matlab中是否有类似的东西,以便我可以匹配元素,然后以类似于如果元素X匹配Y然后.. else ..的方式查询matlab。



谢谢!

解决方案

一个 map 对象。它们非常易于使用。您可以创建一个,如下所示:

  someMap = containers.Map(); 

添加一个新钥匙非常容易

  someMap('someKey')='someValue'; 

默认情况下,该键必须是字符串,但可以编辑该键。您也可以通过调用

  someMap.isKey('someKey')

值可以通过调用

  someMap('someKey')

这应该模仿您正在寻找的行为。您可以通过查看文档来阅读更多内容。


In Haskell, there is a structure called 'tuples' which allows two elements to be paired together (Ie: (1,2), ('A', 'B') etc)

I was wondering if there was something similar in Matlab so that I could match elements and then query matlab in a way similar to "If element X is matched to Y then.. else.."

Thanks!

解决方案

The closet thing I know of in MATLAB is to use a map object. They are pretty easy to use. You can create one as follows

someMap = containers.Map();

Adding a new key is pretty easy as well

someMap('someKey') = 'someValue';

The key needs to be a string by default, but this can be edited. You can also check if the key exists already by calling

someMap.isKey('someKey')

And values are accessed by just calling

someMap('someKey')

This should mimic the behavior that you are looking for. You can always read more by looking at the documentation. containers.Map

这篇关于Matlab中的元组结构等价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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