Code covered by the BSD License  

Highlights from
JSONlab: a toolbox to encode/decode JSON files in MATLAB/Octave

image thumbnail

JSONlab: a toolbox to encode/decode JSON files in MATLAB/Octave

by

 

19 Oct 2011 (Updated )

JSONlab is an open-source JSON/UBJSON encoder and decoder (parser) for MATLAB and Octave.

s=mergestruct(s1,s2)
function s=mergestruct(s1,s2)
%
% s=mergestruct(s1,s2)
%
% merge two struct objects into one
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% date: 2012/12/22
%
% input:
%      s1,s2: a struct object, s1 and s2 can not be arrays
%
% output:
%      s: the merged struct object. fields in s1 and s2 will be combined in s.
%
% license:
%     Simplified BSD License
%
% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%

if(~isstruct(s1) || ~isstruct(s2))
    error('input parameters contain non-struct');
end
if(length(s1)>1 || length(s2)>1)
    error('can not merge struct arrays');
end
fn=fieldnames(s2);
s=s1;
for i=1:length(fn)              
    s=setfield(s,fn{i},getfield(s2,fn{i}));
end

Contact us