MATLAB: Create new table variable filled with values from another table

MATLABtable

Hi. I have the following tabels, T1 and T2:
Name1=["A","B","C","D"]'
Des1=["Shoubidou","Abra","Ca","Dabra"]'
T1=table(Name1, Des1)
Name2 =["C","B","B","A","B","B","A"]'
T2 = table(Name2)
I would like to create a new variable Des2 (in table T2), which for each T2 element contains the description taken from T1. The final result should be:
Des2=["Ca","Abra","Abra","Shoubidou","Abra","Abra","Shoubidou"]'
T2final = table(Name2, Des2)
One way to do this is to iterate over the elements of T2. Is there any other way without a for-loop?
Notice that some elements in T1 it is possible that they are not contained in T2 (just in case this changes your solution).

Best Answer

Try this
Name1=["A","B","C","D"]'
Des1=["Shoubidou","Abra","Ca","Dabra"]'
T1=table(Name1, Des1)
Name2 =["C","B","B","A","B","B","A"]'
T2 = table(Name2)
[~, idx] = ismember(Name2, Name1);
T2.Des2 = Des1(idx);