source: trunk/src/copyfields.m @ 785

Last change on this file since 785 was 19, checked in by gostiaux, 15 years ago

the private files have been moved down to the root folder

File size: 845 bytes
Line 
1%'copyfields' copy fields between two matlab structures
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% OUPUT:
4% NewData: resulting structure
5%
6%INPUT:
7% listfields: cell arrays representing the list of field names to be copied
8% SourceData: structure containing the source data to copy in NewData
9% OldData: (optional) preexisting data structure.
10
11function NewData=copyfields(listfields,SourceData,OldData)
12if ~exist('OldData','var')
13    OldData=[];
14end
15NewData=OldData;%default
16for ifield=1:length(listfields)
17    if isfield(SourceData,listfields{ifield}) & ~isempty(eval(['SourceData.' listfields{ifield}]))
18        eval(['NewData.' listfields{ifield} '=SourceData.' listfields{ifield} ';']);
19    elseif isfield(OldData,listfields{ifield})
20        NewData=rmfield(NewData,listfields{ifield});
21    end
22end
Note: See TracBrowser for help on using the repository browser.