source: trunk/src/copyfields.m @ 867

Last change on this file since 867 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 1.7 KB
Line 
1%'copyfields' copy fields between two matlab structures
2%------------------------------------------------------------------------
3% OUTPUT:
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
11%=======================================================================
12% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
13%   http://www.legi.grenoble-inp.fr
14%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
15%
16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
19%     it under the terms of the GNU General Public License as published
20%     by the Free Software Foundation; either version 2 of the license,
21%     or (at your option) any later version.
22%
23%     UVMAT is distributed in the hope that it will be useful,
24%     but WITHOUT ANY WARRANTY; without even the implied warranty of
25%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
29function NewData=copyfields(listfields,SourceData,OldData)
30if ~exist('OldData','var')
31    OldData=[];
32end
33NewData=OldData;%default
34for ifield=1:length(listfields)
35    if isfield(SourceData,listfields{ifield}) & ~isempty(eval(['SourceData.' listfields{ifield}]))
36        eval(['NewData.' listfields{ifield} '=SourceData.' listfields{ifield} ';']);
37    elseif isfield(OldData,listfields{ifield})
38        NewData=rmfield(NewData,listfields{ifield});
39    end
40end
Note: See TracBrowser for help on using the repository browser.