Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 9/Programming Assignment - 8/ex8/lib/jsonlab/mergestruct.m
626 views
1
function s=mergestruct(s1,s2)
2
%
3
% s=mergestruct(s1,s2)
4
%
5
% merge two struct objects into one
6
%
7
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
8
% date: 2012/12/22
9
%
10
% input:
11
% s1,s2: a struct object, s1 and s2 can not be arrays
12
%
13
% output:
14
% s: the merged struct object. fields in s1 and s2 will be combined in s.
15
%
16
% license:
17
% BSD, see LICENSE_BSD.txt files for details
18
%
19
% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
20
%
21
22
if(~isstruct(s1) || ~isstruct(s2))
23
error('input parameters contain non-struct');
24
end
25
if(length(s1)>1 || length(s2)>1)
26
error('can not merge struct arrays');
27
end
28
fn=fieldnames(s2);
29
s=s1;
30
for i=1:length(fn)
31
s=setfield(s,fn{i},getfield(s2,fn{i}));
32
end
33
34
35