1

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?

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.