How to append labels from one table to another based on certain conditions?
1 次查看(过去 30 天)
显示 更早的评论
I have 2 tables in MATLAB, table X and Table Y each of different dimensions. Table X and Table Y both contain a column named Code. Table X has the last column as LabelX (an empty column) and Table Y has the Last Column LabelY (with label values as strings). What I would like to achieve is that for all elements in Table X, I would like to add the Label from Table Y's LabelY corresponding to the Code. So, for example if Code is 1 in table X, MATLAB would look for the LabelY in Table Y's LabelY column and then append the same label to Table X's LabelX Column. I tried using for loops for this purpose but I don't feel that it is a good way or if I am doing it correctly. Any help in this regard would be appreciated.
for i = 1:size(TableX,1)
for j = 1:size(TableY,1)
if(TableX.Code(i) == TableY(j))
TableA.Label(i) = LDTUniqueAlarmListv3.FunctionalGrouping(j);
end
end
end
0 个评论
采纳的回答
Guillaume
2018-12-4
joinedTable = outerjoin(tableA, tableB, 'Keys', 'Code', 'Type', 'left', 'MergeKeys', true)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!