0001 function [ stdCell ] = stdFieldInCells( cellArray, fieldName )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 isAllField = false;
0022 if nargin == 1
0023 isAllField = true;
0024 end
0025 nCell = length(cellArray);
0026 if nCell == 0
0027 error('Input cell array is empty.');
0028 end
0029
0030 if isAllField == true
0031 stdCell = [];
0032 allFieldName = fieldnames(cellArray{1});
0033 nField = length(allFieldName);
0034
0035 for iField = 1:nField
0036 iFieldName = allFieldName{iField};
0037 iFieldValue = getfield(cellArray{1}, iFieldName);
0038 if ~isnumeric(iFieldValue)
0039 continue;
0040 end
0041 stdFieldValue = stdSpecificField(cellArray, iFieldName);
0042 stdCell = setfield(stdCell, iFieldName, stdFieldValue);
0043 end
0044 else
0045 stdCell = stdSpecificField(cellArray, fieldName);
0046 end
0047 end
0048
0049 function [ stdFieldValue ] = stdSpecificField( cellArray, fieldName )
0050
0051
0052 nCell = length(cellArray);
0053 fieldValue = full(getfield(cellArray{1}, fieldName));
0054 if ~isnumeric(fieldValue)
0055 error([fieldName, ' is not numeric.']);
0056 end
0057 catDimIx = find(size(fieldValue) == 1, 1);
0058 if isempty(catDimIx)
0059 catDimIx = numel(size(fieldValue)) + 1;
0060 end
0061
0062
0063 for iCell = 2:nCell
0064 if ~isfield(cellArray{iCell}, fieldName)
0065 error(['No ' fieldName 'field in ' int2str(iCell) 'th structure.']);
0066 end
0067 fieldValue = ...
0068 cat(catDimIx, fieldValue, full(getfield(cellArray{iCell}, fieldName)));
0069 end
0070
0071 stdFieldValue = std(fieldValue, 0, catDimIx);
0072 end