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일

0 개 추천

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

Mekala balaji
Mekala balaji 2016년 11월 8일
It give error: ??? Undefined function or method 'table' for input arguments of type 'cell'.
Guillaume
Guillaume 2016년 11월 9일
Well, that would mean that a) you're using a version so old (<2013b, something you should have said in your question) that you don't have tables and b) you're using the wrong term in your questions since again you don't have tables (and you wrote "I have input table").
So, I actually have no idea what form your input takes, it's obviously not a table. Since you don't have tables you also can't use join.
Assuming your input is a cell array, you can use ismember instead:
c1 = [{'Mek', 'Lahi', 'Raju', 'Ram', 'Krish', 'Mek', 'Ram', 'Balu', 'Raju'}; num2cell('SSFSFFSSS')].'
c2 = {'Mek' 'Lahi' 'Raju' 'Ram' 'Krish' 'Balu'; 'VAL' 'HAT' 'KJI' 'GAT' 'HTY' 'KTY'}.'
[~, matchrow] = ismember(c1(:, 1), c2(:, 1));
c3 = [c1, c2(matchrow, 2)]
Hi, It works, but I have small amendment in my input, and please suggest me how to incorporate this. I have modified my input as below:
Mek S
Lahi S
Raju F
Ram S
Krish F
Mek F
Ram S
Balu S
Raju S
Venk S
Raju S
Chai F
The change in input is some of the names in the first coulmn of the input does not have any match in the reference table, for this kind of case(s) I just want to assign as "Undefined"
The reference table is below:
Mek VAL
Lahi HAT
Raju KJI
Ram GAT
Krish HTY
Balu KTY
My desired output is below:
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
Venk S Undefined
Raju S KJI
Chai F Undefined
Many thnaks in advance.
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'};
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개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2016년 11월 8일

댓글:

2016년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by