2 if isempty(path2KeepList)
6 if ischar(path2KeepList)
7 path2KeepList={path2KeepList};
9 %make sure that all the restrictions are applied i.e.
if {
'a',
'a.b'} is
10 %specified as path2KeepList
'a.b' is used
12 path2KeepList=sort(path2KeepList);
14 nPath=length(path2KeepList);
15 pathCell=cell(nPath,1);
17 pathCell{iPath}=regexp(path2KeepList{iPath},
'([^\.]*)',
'match');
20 lengthVec=cellfun(@length,pathCell);
21 maxPathLength=max(lengthVec);
22 fieldSeqCell=cell(nPath,maxPathLength);
25 fieldSeqCell(iPath,1:lengthVec(iPath))=pathCell{iPath};
28 [field2KeepList,~,indRep]=
unique(fieldSeqCell(:,1));
33 indCell=accumarray(indRep,(1:nPath).
',[],@(x){x}); 34 nUniqueFields=length(indCell); 36 for iField=1:nUniqueFields 37 fieldName=field2KeepList{iField}; 38 subFieldSeqCell=fieldSeqCell(indCell{iField},:); 39 if size(subFieldSeqCell,2)>1 40 subPath2KeepList=sepcell2pathlist(subFieldSeqCell(:,2:end)); 41 InpSubStruct=auxgetfieldstruct(ResStruct,fieldName); 42 ResCell=num2cell(mxberry.core.struct.pathfilterstruct(InpSubStruct,... 44 ResSubStruct=struct(fieldName,ResCell); 46 ResStruct=mxberry.core.struct.binaryunionstruct(ResStruct,... 47 ResSubStruct,@(x,y)y); 53 function SRes=auxgetfieldstruct(SInp,fieldName) 54 SRes=reshape([SInp.(fieldName)],size(SInp)); 57 function pathList=sepcell2pathlist(sepCell) 58 nPath=size(sepCell,1); 61 isnEmpty=~cellfun(@isempty,sepCell(iPath,:)); 62 indLastNotEmpty=find(isnEmpty,1,'last
'); 63 if isempty(indLastNotEmpty) 67 curPathCell=sepCell(iPath,1:indLastNotEmpty); 68 curPathCell=[repmat({'.
'},1,indLastNotEmpty);curPathCell]; %#ok<AGROW> 69 curPath=horzcat(curPathCell{:}); 70 pathList=[pathList,{curPath}]; %#ok<AGROW>
function pathfilterstruct(in InpStruct, in path2KeepList)
PATHFILTERSTRUCT leaves in input structure array only specified paths.
function unique(in inpVec)
UNIQUE for arrays of any type.