How to match the table

1 回表示 (過去 30 日間)
Mekala balaji
Mekala balaji 2016 年 11 月 8 日
コメント済み: Mekala balaji 2016 年 11 月 11 日
Hi,
I have input table and reference table:
Input Table:
Mek S
Lahi S
Raju F
Ram S
Krish F
Mek F
Ram S
Balu S
Raju S
Reference:
Mek VAL
Lahi HAT
Raju KJI
Ram GAT
Krish HTY
Balu KTY
1. I want to match names of first column of input table, and extract the corresponding name in column2 of Reference table. I want the below output:
Mek S VAL
Lahi S HAT
Raju F KJI
Ram S GAT
Krish F HTY
Mek F VAL
Ram S GAT
Balu S KTY
Raju S KJI
Many thanks in advance

採用された回答

Guillaume
Guillaume 2016 年 11 月 8 日
Have you tried join?
%in the future make it easy to use your example in code by using valid matlab syntax
t1 = table({'Mek', 'Lahi', 'Raju', 'Ram', 'Krish', 'Mek', 'Ram', 'Balu', 'Raju'}.', num2cell('SSFSFFSSS').', 'VariableNames', {'Key', 'Value'})
t2 = table({'Mek' 'Lahi' 'Raju' 'Ram' 'Krish' 'Balu'}.', {'VAL' 'HAT' 'KJI' 'GAT' 'HTY' 'KTY'}.', 'VariableNames', {'Key', 'OtherValue'})
join(t1, t2)
  5 件のコメント
Guillaume
Guillaume 2016 年 11 月 11 日
[isfound, matchrow] = ismember(c1(:, 1), c2(:, 1));
c3 = [c1, cell(size(c1, 1), 1)];
c3(isfound, 2) = c2(matchrow(isfound), 2);
c3(~isfound, 2) = {'Undefined'};
Mekala balaji
Mekala balaji 2016 年 11 月 11 日
Sir,
Thanks But third row is empty as shown below the simulated output (Actual 2nd row missing): c3 =
'Mek' 'VAL' []
'Lahi' 'HAT' []
'Raju' 'KJI' []
'Ram' 'GAT' []
'Krish' 'HTY' []
'Mek' 'VAL' []
'Ram' 'GAT' []
'Balu' 'KTY' []
'Raju' 'KJI' []
'Venk' 'Undefined' []
'Raju' 'KJI' []
'Chai' 'Undefined' []

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeApplication Deployment についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by