Home > matutils > buffields.m

buffields

PURPOSE ^

function [s,b]=buffields(s,fd)

SYNOPSIS ^

function [s,b]=buffields(s,fd)

DESCRIPTION ^

 function [s,b]=buffields(s,fd)

 removes field specified in fd from structure s and stores field
 values and names in buffered structure, b.

 s  - input structure
 fd - cell array of field names, {{'vis'},{'flags','visFlag'}}}
      - will remove fields vis, and flag.visFlag
 b  - structure with fields specified in fd

 Michael Loh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [s,b]=buffields(s,fd)
0002 
0003 % function [s,b]=buffields(s,fd)
0004 %
0005 % removes field specified in fd from structure s and stores field
0006 % values and names in buffered structure, b.
0007 %
0008 % s  - input structure
0009 % fd - cell array of field names, {{'vis'},{'flags','visFlag'}}}
0010 %      - will remove fields vis, and flag.visFlag
0011 % b  - structure with fields specified in fd
0012 %
0013 % Michael Loh
0014 
0015 b=[];
0016 for i=1:length(fd)
0017   if (length(fd{i})==1)
0018     if (isfield(s,fd{i}))
0019       eval(sprintf('b.%s=s.%s;', char(fd{i}), char(fd{i})));
0020       s=rmfield(s,fd{i});
0021     end
0022   else
0023     rm=1;
0024     for j=1:length(fd{i})
0025       if (j==1)
0026     str='';
0027       else
0028     str=strcat(str,sprintf('.%s',char(fd{i}{j-1})));
0029       end
0030       if (~eval(sprintf('isfield(s%s,''%s'')',str,char(fd{i}{j}))))
0031     rm=0;
0032     break;
0033       end
0034     end
0035     if (rm)
0036       str2=strcat(str,sprintf('.%s',char(fd{i}{j})));
0037       eval(sprintf('b%s=s%s;', str2, str2));
0038       eval(sprintf('s%s=rmfield(s%s,fd{i}{j});',str,str));
0039     end
0040   end
0041 end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005