MATLAB: Joining a table using a column of list

column of arraysdata wranglingjoin;table

Hi all, I have two tables as shown:
Table A (size mxn):
VarA VarB …..
—— ——-
3 [1, 5, 7]
167 [2, 6, 9, 11]
……
Table B (size axb):
VarC VarD …..
—— ——-
1 "X"
2 "B"
5 "E"
6 "F"
7 "G"
9 "I"
11 "R"
I would like to make use of Table B to join a new column to Table A like below:
New Table A:
VarA VarB VarE …..
—— ——- ——-
3 [1, 5, 7] ["X", "E", "G"]
167 [2, 6, 9, 11] ["B", "F", "I", "R"]
……
Any help is much appreciated.

Best Answer

  • Try this
    if true
    tabA.VarE = cellfun(@(X)tabB.VarD(ismember(tabB.VarC,X)),tabA.VarB,'UniformOutput',false);
    end