MatrixBerryCore
getleavelist.m
Go to the documentation of this file.
1 function [pathSpecList,valueList]=getleavelist(SInp)
2 pathSpecList=getleavelistint(SInp);
3 if nargout>1
4  nLeaves=length(pathSpecList);
5  valueList=cell(nLeaves,1);
6  for iLeave=1:nLeaves
7  valueList{iLeave}=getfield(SInp,pathSpecList{iLeave}{:});
8  end
9 end
10 end
11 function pathList=getleavelistint(SInp)
12 import mxberry.core.throwerror;
13 if ~isstruct(SInp)
14  throwerror('wrongInput',...
15  'SInp is expected to be a structure array');
16 end
17 %
18 fieldNameList=fieldnames(SInp);
19 nFields=numel(fieldNameList);
20 %
21 if nFields>0
22  nElems=numel(SInp);
23  indVec=nElems:-1:1;
24  indCMat=num2cell(mxberry.core.ind2submat(size(SInp),indVec));
25  pathSpecCell=cell(nElems,nFields);
26  for iElem=indVec
27  for iField=1:nFields
28  SCur=SInp(iElem).(fieldNameList{iField});
29  if isstruct(SCur)&&~isempty(fieldnames(SCur))
30  pathSpecCell{iElem,iField}=...
31  getleavelistint(SCur);
32  %
33  pathSpecCell{iElem,iField}=cellfun(...
34  @(x)[{indCMat(iElem,:)},fieldNameList(iField), x],...
35  pathSpecCell{iElem,iField},...
36  'UniformOutput',false);
37  %
38  else
39  pathSpecCell{iElem,iField}=...
40  {{indCMat(iElem,:),fieldNameList{iField}}};
41  end
42  end
43  end
44  pathList=vertcat(pathSpecCell{:});
45 else
46  pathList=cell(0,0);
47 end
48 end
function num2cell(in inpArray, in varargin)
NUM2CELL is an extension of Matlab built-in function "num2cell" designed to work correctly with empty...
function getleavelist(in SInp)
GETLEAVELIST generates a list of structure leave paths.
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function getleavelistint(in SInp)