-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfillstruct.m
More file actions
35 lines (33 loc) · 1.18 KB
/
fillstruct.m
File metadata and controls
35 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function filled=fillstruct(def, prov)
% Check fields from provided struct against default struct
% FORMAT filled=fillstruct(def, prov)
% ======
% Input Arguments
% def - Struct containing all required fields and their default values
% prov - Struct array containing fields that will override defaults
% Output Argument
% filled - Struct array containing field values from prov, if given,
% otherwise from def struct.
% Only fields which are in def struct are checked and returned. Thus, prov
% can not add new fields to an existing default struct.
% If prov contains an struct array, fields are checked for each
% individual array member and a filled struct array is returned.
%_______________________________________________________________________
%
% @(#) $Id: fillstruct.m 552 2006-06-08 06:26:38Z volkmar $
rev = '$Revision: 552 $';
if isempty(prov)
filled = def;
else
fnames = fieldnames(def);
filled(1:numel(prov)) = deal(def);
for k = 1:numel(fnames)
if isfield(prov(1),fnames{k})
% if 1st element has this field, then all in prov array have it
for l=1:numel(prov)
filled(l).(fnames{k}) = prov(l).(fnames{k});
end;
end;
end;
end;
return;