Reputation: 111
My matrix currently looks like this
1 225 230 300
4 333 442 678
7 798 782 128
1 248 842 482
Coloumn 1 is a series of numbers which I have mapped to another set of numbers. for example
KeySet = (1:42)
ValueSet = (333, 222, 4444, 7778 etc etc to 42 numbers)
mapObj = containers.Map(KeySet, ValueSet)
Now I want to create a new coloumn in my original matrix coloumn 5 which will be populated from the ValueSet with reference to the mapping - so row 1 coloumn 5 will be 333 and row 2 coloumn 5 will be 7778 and so on. Its essentially a vlookup from coloumn 5 into the mapping.
It would look something like this I would guess
mat(:,5) = mapObj(mat(:,1))
Upvotes: 1
Views: 46
Reputation: 36710
You can't query a mapobject for multiple entries at once, i would use arrayfun
:
arrayfun(@(ix)mapObj(ix),mat(:,1))
In your example the key set is 1:n, if this is always the case then use an array instead of a map, it's much faster and you can index multiple entries at once.
Upvotes: 0