Last change
on this file since 299 was
19,
checked in by gostiaux, 15 years ago
|
the private files have been moved down to the root folder
|
File size:
845 bytes
|
Rev | Line | |
---|
[8] | 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 | |
---|
| 11 | function NewData=copyfields(listfields,SourceData,OldData) |
---|
| 12 | if ~exist('OldData','var') |
---|
| 13 | OldData=[]; |
---|
| 14 | end |
---|
| 15 | NewData=OldData;%default |
---|
| 16 | for 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 |
---|
| 22 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.