Add contents of two columns to new columns with a delimiter between them
Mostra commenti meno recenti
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?
Risposte (2)
dpb
il 24 Mag 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?
5 Commenti
Rogier Busscher
il 24 Mag 2017
dpb
il 25 Mag 2017
Well, it'll work...
> find(key=='3|3')
ans =
3
but, you don't need it, either, unless you just want the appearance of the combined locations. The categorical is kinda' good about that.
But, get to same place with
> find(ismember(rb(:,[1:2]),[3 3],'rows'))
ans =
3
>>
directly from the two values.
Rogier Busscher
il 25 Mag 2017
Rogier Busscher
il 25 Mag 2017
dpb
il 26 Mag 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.
Walter Roberson
il 25 Mag 2017
0 voti
If you only need to know what the distance is for each combination, but you do not need the path for each combination, then you can use https://www.mathworks.com/help/matlab/ref/graph.distances.html
If you need to know the path, then you can loop through all sources and use https://www.mathworks.com/help/matlab/ref/graph.shortestpath.html to all destinations.
Categorie
Scopri di più su Repeated Measures and MANOVA in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!