## Add contents of two columns to new columns with a delimiter between them

### Rogier Busscher (view profile)

on 24 May 2017
Latest activity Commented on by dpb

### dpb (view profile)

on 26 May 2017
I have a matrix of 11693682x3 uint8. I would like to create so called 'keys' for my data in a new column. For example:
1, 2, 3
2, 5, 7
3, 3, 6,
4, 29, 0
Output:
1, 2, 3, 1|2
2, 5, 7, 2|5
3, 3, 6, 3|3
4, 29, 0, 4|29
Could anyone point me at the best way to solve this?

### dpb (view profile)

on 24 May 2017

Well, it's simply impossible to add something like that as another column in an int8 array.
To do something similar you could create a corollary variable
>> key=categorical(cellstr(num2str(rb(:,1:2),'%d|%d')))
key =
1|2
2|5
3|3
4|29
>>
I'd suggest more conventional hashing techniques might be more useful, though. What's the end use here?

Rogier Busscher

### Rogier Busscher (view profile)

on 25 May 2017
I do not think i've made myself fully clear. I got a 11318560x3 matrix of all possible combination of Origin, Station and Destination.
Furthermore, i have travel time data on:
Any origin (A) to any station(B).
Any station(B) to any destination(C).
So i want to link the trips to that begin and end at the same station. That will result into a matrix of data where 'people' go from every origin to every destination, by using every station possible (A|B|C)
Then, I must find the lowest value for every origin-destination (A|C), so that i know what the lowest possible travel time is between each origin and destination.
So that is where i want to use the keys for, because it should be possible to find the lowest value in column K for each unique value (the keys) in Column J
Rogier Busscher

### Rogier Busscher (view profile)

on 25 May 2017
But if you have a faster/better solution for this problem, i'm open to suggestions.
dpb

### dpb (view profile)

on 26 May 2017
I thought you were looking for a way to find the given pair; the above does that by locating where that pair is in the vector.
If it's two sets, then just combination of
key1==val1 & key2==val2
is the same result.