Added feature to merge 2 tables, not only to add a row to a table
This commit is contained in:
1 parent
20577d00be
commit
683e0198e6
2 files changed
+668
-662
No files matched your search
@@ -6,7 +6,7 @@ function Table = outerjoinRowToTable(Table,TableRowToBeAdded)
|
||||
%
|
||||
% * Strings in the table are not yet supported.
|
||||
% * The row that is added needs to be formated as table
|
||||
% * Adds only one row at a time%
|
||||
% * Adds only one row at a time. Update 2024: Adds several rows, that is tables
|
||||
%
|
||||
% T = outerjoinRowToTable(TableToAddTo,RowToBeAdded)
|
||||
%
|
||||
@@ -21,11 +21,14 @@ if ~all(ismember(Table.Properties.VariableNames,TableRowToBeAdded.Properties.Var
|
||||
tmpMissingVariable = ~ismember(Table.Properties.VariableNames,TableRowToBeAdded.Properties.VariableNames);
|
||||
tmpVariablesToBeAdded = Table.Properties.VariableNames(tmpMissingVariable);
|
||||
for ii = 1:size(tmpVariablesToBeAdded,2)
|
||||
if matches(class(Table.(tmpVariablesToBeAdded{ii})),'double')
|
||||
tmpContentToBeAdded = NaN(1,size(Table.(tmpVariablesToBeAdded{ii}),2));
|
||||
if matches(class(Table.(tmpVariablesToBeAdded{ii})),'double') || matches(class(Table.(tmpVariablesToBeAdded{ii})),'int32')
|
||||
tmpContentToBeAdded = NaN(size(TableRowToBeAdded,1),size(Table.(tmpVariablesToBeAdded{ii}),2));
|
||||
TableRowToBeAdded = addvars(TableRowToBeAdded,tmpContentToBeAdded,'NewVariableNames',tmpVariablesToBeAdded{ii});
|
||||
elseif matches(class(Table.(tmpVariablesToBeAdded{ii})),'cell')
|
||||
tmpContentToBeAdded = {' '};
|
||||
tmpContentToBeAdded = repmat({' '},size(TableRowToBeAdded,1),size(Table.(tmpVariablesToBeAdded{ii}),2));
|
||||
TableRowToBeAdded = addvars(TableRowToBeAdded,tmpContentToBeAdded,'NewVariableNames',tmpVariablesToBeAdded{ii});
|
||||
elseif matches(class(Table.(tmpVariablesToBeAdded{ii})),'string')
|
||||
tmpContentToBeAdded = repmat({" "},size(TableRowToBeAdded,1),size(Table.(tmpVariablesToBeAdded{ii}),2));
|
||||
TableRowToBeAdded = addvars(TableRowToBeAdded,tmpContentToBeAdded,'NewVariableNames',tmpVariablesToBeAdded{ii});
|
||||
end
|
||||
end
|
||||
@@ -35,11 +38,14 @@ if ~all(ismember(TableRowToBeAdded.Properties.VariableNames,Table.Properties.Var
|
||||
tmpMissingVariable = ~ismember(TableRowToBeAdded.Properties.VariableNames,Table.Properties.VariableNames);
|
||||
tmpVariablesToBeAdded = TableRowToBeAdded.Properties.VariableNames(tmpMissingVariable);
|
||||
for ii = 1:size(tmpVariablesToBeAdded,2)
|
||||
if matches(class(TableRowToBeAdded.(tmpVariablesToBeAdded{ii})),'double')
|
||||
if matches(class(TableRowToBeAdded.(tmpVariablesToBeAdded{ii})),'double') || matches(class(TableRowToBeAdded.(tmpVariablesToBeAdded{ii})),'int32')
|
||||
tmpContentToBeAdded = NaN(size(Table,1),size(TableRowToBeAdded.(tmpVariablesToBeAdded{ii}),2));
|
||||
Table = addvars(Table,tmpContentToBeAdded,'NewVariableNames',tmpVariablesToBeAdded{ii});
|
||||
elseif matches(class(TableRowToBeAdded.(tmpVariablesToBeAdded{ii})),'cell')
|
||||
tmpContentToBeAdded = repmat({' '},size(Table,1),1);
|
||||
tmpContentToBeAdded = repmat({' '},size(Table,1),size(TableRowToBeAdded.(tmpVariablesToBeAdded{ii}),2));
|
||||
Table = addvars(Table,tmpContentToBeAdded,'NewVariableNames',tmpVariablesToBeAdded{ii});
|
||||
elseif matches(class(TableRowToBeAdded.(tmpVariablesToBeAdded{ii})),'string')
|
||||
tmpContentToBeAdded = repmat({" "},size(Table,1),size(TableRowToBeAdded.(tmpVariablesToBeAdded{ii}),2));
|
||||
Table = addvars(Table,tmpContentToBeAdded,'NewVariableNames',tmpVariablesToBeAdded{ii});
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user