1 function [SRes,isThere]=
structgetpath(SInpArr,pathStr,isPresenceChecked,isJustCheck)
6 throwerror(
'wrongInpt',
'SInpArr is expected to be a structure');
9 if ~(
isstring(pathStr)||ischar(pathStr)&&isempty(pathStr)||...
11 throwerror(
'wrongInpt',[
'pathStr is expected to be ',...
12 'either a string or a list of strings']);
17 isPresenceChecked=
false;
18 elseif ~(islogical(isPresenceChecked)&&isscalar(isPresenceChecked))
20 'isPresenceChecked is expected to be a logical scalar');
22 elseif ~(islogical(isJustCheck)&&isscalar(isJustCheck))
24 'isJustCheck is expected to be a logical scalar');
26 SRes=
struct.empty(0,0);
29 isPresenceChecked=
true;
39 fieldNameList=regexp(pathStr,
'([^\.]*)',
'match');
41 fieldNameList=pathStr;
44 firstField=fieldNameList{1};
47 [SResArr,isThere]=
getField(SInpArr,firstField,...
51 if length(fieldNameList)>1
53 fieldNameList(2:end),isPresenceChecked,isJustCheck);
59 [SResCArr,isThereCArr]=arrayfun(...
60 @(x)
getField(x,firstField,isPresenceChecked),...
61 SInpArr,
'UniformOutput',
false);
62 isThere=all([isThereCArr{:}]);
66 if length(fieldNameList)>1
67 [~,isThereArr]=cellfun(...
69 fieldNameList(2:end),isPresenceChecked,isJustCheck),...
70 SResCArr,
'UniformOutput',
false);
71 isThere=all([isThereArr{:}]);
84 if length(fieldNameList)>1
87 fieldNameList(2:end),isPresenceChecked,...
98 function [SRes,isThere]=
getField(SInpArr,fieldName,isPresenceChecked)
100 if isfield(SInpArr,fieldName)
102 SRes=SInpArr.(fieldName);
105 SRes=
struct.empty(0,0);
108 SRes=SInpArr.(fieldName);
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 structgetpath(in SInpArr, in pathStr, in isPresenceChecked, in isJustCheck)
STRUCTGETPATH extract a value from a given structure array using a path specified either as a string ...
function iscellofstring(in inpArray)
function isstring(in inpArray)
function cell2mat(in inpCArr)
CELL2MAT does the same as the built-in cell2mat function but a) 20% faster b) works with cell arrays ...
function getField(in SInpArr, in fieldName, in isPresenceChecked)