ATGETFIELDVALUES retrieves the field values AT cell array of elements VALUES = ATGETFIELDVALUES(RING,'field') extracts the values of the field 'field' in all the elements of RING VALUES = ATGETFIELDVALUES(RING,INDEX,'field') extracts the values of the field 'field' in the elements of RING selected by INDEX if RING{I}.FIELD is a numeric scalar VALUES is a length(INDEX) x 1 array otherwise VALUES is a length(INDEX) x 1 cell array More generally ATGETFIELDVALUES(RING,INDEX,subs1,subs2,...) will call GETFIELD(RING{I},subs1,subs2,...) for I in INDEX Examples: V=ATGETFIELDVALUES(RING,1:10,'PolynomB') is a 10x1 cell array such that V{I}=RING{I}.PolynomB for I=1:10 V=ATGETFIELDVALUES(RING(1:10),'PolynomB',{1,2}) is a 10x1 array such that V(I)=RING{I},PolynomB(1,2) See also ATSETFIELDVALUES ATGETCELLS GETCELLSTRUCT FINDCELLS
0001 function values = atgetfieldvalues(ring,varargin) 0002 %ATGETFIELDVALUES retrieves the field values AT cell array of elements 0003 % 0004 % VALUES = ATGETFIELDVALUES(RING,'field') extracts the values of 0005 % the field 'field' in all the elements of RING 0006 % 0007 % VALUES = ATGETFIELDVALUES(RING,INDEX,'field') extracts the values of 0008 % the field 'field' in the elements of RING selected by INDEX 0009 % 0010 % if RING{I}.FIELD is a numeric scalar 0011 % VALUES is a length(INDEX) x 1 array 0012 % otherwise 0013 % VALUES is a length(INDEX) x 1 cell array 0014 % 0015 % 0016 % More generally ATGETFIELDVALUES(RING,INDEX,subs1,subs2,...) will call 0017 % GETFIELD(RING{I},subs1,subs2,...) for I in INDEX 0018 % 0019 % Examples: 0020 % 0021 % V=ATGETFIELDVALUES(RING,1:10,'PolynomB') is a 10x1 cell array 0022 % such that V{I}=RING{I}.PolynomB for I=1:10 0023 % 0024 % V=ATGETFIELDVALUES(RING(1:10),'PolynomB',{1,2}) is a 10x1 array 0025 % such that V(I)=RING{I},PolynomB(1,2) 0026 % 0027 % 0028 % See also ATSETFIELDVALUES ATGETCELLS GETCELLSTRUCT FINDCELLS 0029 0030 if islogical(varargin{1}) || isnumeric(varargin{1}) 0031 values=atgetfield(ring(varargin{1}),varargin{2:end}); 0032 else 0033 values=atgetfield(ring,varargin{:}); 0034 end 0035 0036 function values = atgetfield(line,varargin) 0037 [values,isnumscal,isok]=cellfun(@scan,line(:),'UniformOutput',false); 0038 isok=cat(1,isok{:}); 0039 if all(cat(1,isnumscal{isok})) 0040 values(~isok)={NaN}; 0041 values=cat(1,values{:}); 0042 end 0043 0044 function [val,isnumscal,isok]=scan(el) 0045 try 0046 val=getfield(el,varargin{:}); 0047 isnumscal=isnumeric(val) && isscalar(val); 0048 isok=true; 0049 catch 0050 val=[]; 0051 isnumscal=false; 0052 isok=false; 0053 end 0054 end 0055 end 0056 0057 end