LTPDA_STRUCTIDX Index a structure. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: LTPDA_STRUCTIDX Index a structure. All fields are assumed to be vectors of the same length, except those explicitely ignored. You can give an additional list of field names which will be ignored in the indexing. CALL: sout = ltpda_structidx(sin, idx) = ltpda_structidx(sin, idx, 'field1', 'field2') INPUTS: sin - a struct idx - index field1 - field name field2 - field name ... OUTPUTS: sout - a struct VERSION: $Id: ltpda_structidx.m,v 1.5 2007/07/13 12:17:39 ingo Exp $ HISTORY: 26-01-2007 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function sout = ltpda_structidx(sin, idx, varargin) 0002 % LTPDA_STRUCTIDX Index a structure. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: LTPDA_STRUCTIDX Index a structure. All fields are assumed 0007 % to be vectors of the same length, except those explicitely ignored. 0008 % 0009 % You can give an additional list of field names which will be 0010 % ignored in the indexing. 0011 % 0012 % CALL: sout = ltpda_structidx(sin, idx) 0013 % = ltpda_structidx(sin, idx, 'field1', 'field2') 0014 % 0015 % INPUTS: sin - a struct 0016 % idx - index 0017 % field1 - field name 0018 % field2 - field name 0019 % ... 0020 % 0021 % OUTPUTS: sout - a struct 0022 % 0023 % VERSION: $Id: ltpda_structidx.m,v 1.5 2007/07/13 12:17:39 ingo Exp $ 0024 % 0025 % HISTORY: 26-01-2007 M Hewitson 0026 % Creation 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 Nigf = nargin-2; 0031 0032 % examine fields 0033 fields = fieldnames(sin); 0034 nf = length(fields); 0035 0036 for f=1:nf 0037 fn = char(fields(f)); 0038 skip = 0; 0039 for j=1:Nigf 0040 0041 if strcmp(fn, char(varargin{j})) 0042 skip = 1; 0043 str = sprintf('sout.%s = sin.%s;', fn, fn); 0044 eval(str); 0045 end 0046 0047 end 0048 0049 if ~skip 0050 str = sprintf('sout.%s = sin.%s(idx);', fn, fn); 0051 eval(str); 0052 end 0053 end 0054 0055 0056 0057 0058 0059 % END