Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...