Create tables based on matching columns by identical names
2 views (last 30 days)
Show older comments
Hi,
I have two tables with four separate columns. Each column in each table has a unique variable name. However, the variable names match between position 5 and 10 for two columns (one in each table). I want to create four new tables consisting of two columns where the variable names match. So far, I have tried the following:
names5 = Table_A.Properties.VariableNames;%1
names6 = Table_B.Properties.VariableNames;%1
matchVals = {'1234', '5678','9101','1123'}; %part of the variable names that match => four new tables
numTables = numel(matchVals);
%%
tableNames_ = cell(numTables,1);
for k = 1:numel(matchVals)
idl5 = cellfun(@(x) strcmp(x(5),matchVals{k})... %assessing position 5 to 10 for correct variable names
&&strcmp(x(6),matchVals{k})...
&&strcmp(x(7),matchVals{k})...
&&strcmp(x(8),matchVals{k})...
&&strcmp(x(9),matchVals{k})...
&&strcmp(x(10),matchVals{k}),names5);
idl6 = cellfun(@(x) strcmp(x(5),matchVals{k})...%assessing position 5 to 10 for correct variable names
&&strcmp(x(6),matchVals{k})...
&&strcmp(x(7),matchVals{k})...
&&strcmp(x(8),matchVals{k})...
&&strcmp(x(9),matchVals{k})...
&&strcmp(x(10),matchVals{k}),names6);
%
eval(['Summary',matchVals{k},' = [Table_A(:,idl5) Table_B(:,idl6)]']);
tableNames_EC2217{k} = ['Summary',matchVals{k}]; %trying to create new table
end
The code runs, but my columns are not matched. I.e. my out put includes the new tables but without any row values from the original tables.
Any help is appreciated.
0 Comments
Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!