Last change
on this file since 4 was
4,
checked in by zhangj, 10 years ago
|
Initial import--MML version from SOLEIL@2013
|
File size:
818 bytes
|
Line | |
---|
1 | function str = structmerge(str1,str2) |
---|
2 | %============================================================= |
---|
3 | %merge fields of two structures (single field deep) |
---|
4 | %Note: for speed str1 is longer than str2 |
---|
5 | if isempty(str1) str=str2; return; end |
---|
6 | if isempty(str2) str=str1; return; end |
---|
7 | |
---|
8 | s1=size(str1); |
---|
9 | s2=size(str2); |
---|
10 | if ~(s1(2)==s2(2)) |
---|
11 | disp('Warning: structure sizes not equal in structmerge'); |
---|
12 | end |
---|
13 | |
---|
14 | for jj=1:s2(2) %...loop over all instances |
---|
15 | st=str1(jj); |
---|
16 | fn2=fieldnames(str2(jj)); |
---|
17 | for ii=1:length(fn2); %...loop over all fields |
---|
18 | fname=fn2{ii}; |
---|
19 | if ~isfield(str1(jj),fname); |
---|
20 | val=getfield(str2(jj),fname); |
---|
21 | st=setfield(st,fname,val); |
---|
22 | else |
---|
23 | disp(['Warning in structmerge: common ''' fname ''' field in structures']); |
---|
24 | end |
---|
25 | end |
---|
26 | str(jj)=st; |
---|
27 | end %...end depth of structure |
---|
Note: See
TracBrowser
for help on using the repository browser.