Reputation: 333
I would like to store values in the way that every value is mapped onto either 1 or 0. For example:
3 => 0
6 => 1
9 => 1
7 => 1
For a given value I would like to be able to find all other values with the same mapped value. In this example value 6 would also yield values 9 and 7.
What is the best solution in matlab?
Upvotes: 1
Views: 770
Reputation: 11810
If the only thing you need is to have some value assigned to some other real numbers (this is at least what it looks like in your question), you should simply use arrays:
idx = [3 6 9 7];
val = [0 1 1 1];
now you can extract all indices with a 1 or 0 using find
idx(find(val==1))
ans =
6
7
9
idx(find(val==0))
ans =
3
Upvotes: 3
Reputation: 41002
Check this out. the data structure you are describing called a hashmap
or a map
.
e.g.
keySet = {'Jan', 'Feb', 'Mar', 'Apr'};
valueSet = [327.2, 368.2, 197.6, 178.4];
mapObj = containers.Map(keySet,valueSet)
This code returns a description of the map, including the property values:
mapObj =
containers.Map handle
Package: containers
Properties:
Count: 4
KeyType: 'char'
ValueType: 'double'
Methods, Events, Superclasses
Upvotes: 1