Mercurial > repos > public > sbplib
view copyWithDefault.m @ 572:4a73b2aab91f feature/utux2D
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Thu, 31 Aug 2017 14:57:34 +0200 |
parents | 499653b553b8 |
children |
line wrap: on
line source
% Copy the struct src to dest with default values from default % dest = copyWithDefault(src, default) function dest = copyWithDefault(src, default) % src does not have a value => use default if isempty(src) dest = default; return end % src has a value and is not a struct => use src % src has a value and default is not a struct => use src if ~isstruct(src) || ~isstruct(default) dest = src; return end % src has a value and is a struct => add all default fields dest = src; fn = fieldnames(default); for i = 1:length(fn) if isfield(src, fn{i}) srcField = src.(fn{i}); else srcField = []; end dest.(fn{i}) = copyWithDefault(srcField, default.(fn{i})); end end