MatrixBerryCore
fieldfilterstruct.m
Go to the documentation of this file.
1 function ResStruct=fieldfilterstruct(InpStruct,field2KeepList,isCheckField)
2 import mxberry.core.throwerror;
3 if nargin<3
4  isCheckField=false;
5 end
6 if isempty(field2KeepList)
7  ResStruct=InpStruct;
8  return;
9 end
10 %
11 if ischar(field2KeepList)
12  field2KeepList={field2KeepList};
13 end
14 
15 initFieldList=fieldnames(InpStruct);
16 fieldList=setdiff(initFieldList,field2KeepList);
17 ResStruct=rmfield(InpStruct,fieldList);
18 
19 if isCheckField
20  isExist=ismember(field2KeepList,initFieldList);
21  if ~all(isExist(:))
22  indBad=find(~isExist,1,'first');
23  throwerror('wrongFieldName',...
24  'InpStruct does not contain %s field', field2KeepList{indBad});
25  end
26 end
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 fieldfilterstruct(in InpStruct, in field2KeepList, in isCheckField)
FIELDFILTERSTRUCT leaves in input structure array only specified fields.
function ismember(in leftVec, in rightVec, in varargin)
ISMEMBER - ismember implementation for arrays of any type.