Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

haskell - Tuple structure equivalent in Matlab

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...