-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetstructfields.m
More file actions
executable file
·28 lines (23 loc) · 956 Bytes
/
Copy pathsetstructfields.m
File metadata and controls
executable file
·28 lines (23 loc) · 956 Bytes
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
function structout = setstructfields(structin, newfields)
%SETSTRUCTFIELDS Set fields of a structure using another structure
% SETSTRUCTFIELDS(STRUCTIN, NEWFIELDS) Set fields of STRUCTIN using
% another structure NEWFIELDS fields. If fields exist in STRUCTIN
% but not in NEWFIELDS, they will not be changed.
% Author(s): J. Schickler
% Copyright 1988-2004 The MathWorks, Inc.
narginchk(2,2);
% Set the output to the input
structout = structin;
% If newfields is not a structure return
if ~isstruct(newfields), return; end
% Loop over all the fields of newfields and assign them to the output
fields = fieldnames(newfields);
for i = 1:length(fields),
value = newfields.(fields{i});
if isstruct(value) && isfield(structout, fields{i}) && isstruct(structout.(fields{i}))
structout.(fields{i}) = setstructfields(structout.(fields{i}), value);
else
structout.(fields{i}) = newfields.(fields{i});
end
end
% [EOF]