6 % 2.0 (sep 2007) removed bug when dealing with fields containing cell
7 % arrays (Thanks to Rene Willemink)
8 % 2.1 (sep 2008) added warning and error identifiers
9 % 2.2 (oct 2008) fixed error when dealing with empty structs (thanks to
11 % 3.0 (mar 2013) fixed problem when the inputs were array of structures
12 % (thanks to Tor Inge Birkenes).
13 % Rephrased the help section as well.
14 % 4.0 (dec 2013) fixed problem with unique due to version differences in
15 % ML. Unique(...,
'last') is no longer the deafult.
16 % (thanks to Isabel
P)
20 error(nargchk(1,Inf,nargin)) ;
23 if ~isstruct(varargin{
end}),
24 if isequal(varargin{
end},
'sorted'),
27 error(nargchk(1,Inf,N)) ;
29 error(
'catstruct:InvalidArgument',
'Last argument should be a structure, or the string "sorted".') ;
35 sz0 = [] ; % used to check that all inputs have the same size
37 % used to check
for a few trivial cases
38 NonEmptyInputs =
false(
N,1) ;
41 % used to collect the fieldnames and the inputs
49 error(
'catstruct:InvalidArgument',[
'Argument #' num2str(ii)
' is not a structure.']) ;
53 % empty structs are ignored
54 if ii > 1 && ~isempty(sz0)
55 if ~isequal(size(X), sz0)
56 error('
catstruct:UnequalSizes','All structures should have the same size.') ;
61 NonEmptyInputsN = NonEmptyInputsN + 1 ;
62 NonEmptyInputs(ii) = true ;
63 FN{ii} = fieldnames(X) ;
64 VAL{ii} = struct2cell(X) ;
68 if NonEmptyInputsN == 0
69 % all structures were empty
71 elseif NonEmptyInputsN == 1,
72 % there was only one non-empty structure
73 A = varargin{NonEmptyInputs} ;
78 % there is actually something to concatenate
85 [UFN,ind] = unique(FN,
'last') ;
86 % If
this line errors, due to your matlab version not having UNIQUE
87 % accept the
'last' input, use the following line instead
88 % [UFN,ind] = unique(FN) ; % earlier ML versions, like 6.5
90 if numel(UFN) ~= numel(FN),
91 warning(
'catstruct:DuplicatesFound',
'Fieldnames are not unique between structures.') ;
100 A = cell2struct(VAL, FN);
101 A = reshape(A, sz0) ; % reshape into original format
function catstruct(in varargin)
Concatenate or merge structures with different fieldnames.
function N(in obj)
Retrieve the number of signal components.
Property P
Total signal power (pwr object)
function end(in obj, in k, in n)
Overload of indexing end statement.