Now, the function can also deal with columns that have different numbers of entires (such as from peak fitting results)
This commit is contained in:
1 parent
23e49b4330
commit
07e414c3ef
1 file changed
+32
-2
@@ -5,8 +5,9 @@ function Table = outerjoinRowToTable(Table,TableRowToBeAdded)
|
||||
%doubles.
|
||||
%
|
||||
% * 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. Update 2024: Adds several rows, that is tables
|
||||
% * The row that is added needs to be formatted as table
|
||||
% * Update 2024: Adds several rows, that is tables
|
||||
% * Update 2026: Handles peakfitting columns with different size.
|
||||
%
|
||||
% T = outerjoinRowToTable(TableToAddTo,RowToBeAdded)
|
||||
%
|
||||
@@ -50,6 +51,35 @@ if ~all(ismember(TableRowToBeAdded.Properties.VariableNames,Table.Properties.Var
|
||||
end
|
||||
end
|
||||
end
|
||||
% Reconcile column widths for peak-fit columns.
|
||||
% These numeric columns can have variable width (one entry per peak),
|
||||
% so a width mismatch is expected when spectra have different numbers
|
||||
% of peaks. Pad the narrower side with NaN.
|
||||
variableWidthColumns = {'peakArea', 'peakPosition', 'peakFWHM', ...
|
||||
'peakBackground', 'peakEta', 'peakShirleyK'};
|
||||
|
||||
for ii = 1:numel(variableWidthColumns)
|
||||
varName = variableWidthColumns{ii};
|
||||
|
||||
if ~ismember(varName, Table.Properties.VariableNames) || ...
|
||||
~ismember(varName, TableRowToBeAdded.Properties.VariableNames)
|
||||
continue
|
||||
end
|
||||
|
||||
widthT = size(Table.(varName), 2);
|
||||
widthR = size(TableRowToBeAdded.(varName), 2);
|
||||
|
||||
if widthT < widthR
|
||||
Table.(varName) = [Table.(varName), ...
|
||||
NaN(height(Table), widthR - widthT)];
|
||||
elseif widthR < widthT
|
||||
TableRowToBeAdded.(varName) = [TableRowToBeAdded.(varName), ...
|
||||
NaN(height(TableRowToBeAdded), widthT - widthR)];
|
||||
end
|
||||
end
|
||||
|
||||
% Ensure matching column order before concatenation
|
||||
TableRowToBeAdded = TableRowToBeAdded(:, Table.Properties.VariableNames);
|
||||
% Add row to table
|
||||
Table = [Table;TableRowToBeAdded];
|
||||
end
|
||||
Reference in new issue
Block a user