4 robolog('Variable class is supposed to be a
string/
char.','ERR');
7 robolog('Variable param is supposed to be a struct.','ERR');
10 % Get all field names of the param struct
17 props=properties(class);
19 props{find(cellfun(@(x) strcmpi(x,
'nOutputs'),props))}=
'NOPROPERTY';
20 props{find(cellfun(@(x) strcmpi(x,
'nInputs'),props))}=
'NOPROPERTY';
23 members_names=cellfun(@sum,cellfun(@(name) cellfun(@(prop) myRegex(prop,name), props), names,
'UniformOutput',
false))~=0;
25 temp=[{names{members_names}}; {names{members_names}}];
26 eval(sprintf(
'param_copied.%s=param.%s;',temp{:}));
28 %
robolog(
'No parameters match the properties of this unit/module (%s).',
'WRN',
class);
32 function result = myRegex(prop,name)
34 result = ~isempty( regexpi(name,[prop '\>'],'match') );
36 result = ~isempty( regexp(name,[prop '\>'],'match') );
42 names{length(names)+1}={moduleName};
43 for ii=1:length(names)-1
44 if(isModule(names{ii}{1}))
51 if(~isModule(moduleName))
54 text = fileread([moduleName '.m']);
56 [startIndex,endIndex]=regexp(text,'\%.*?\n');
58 for n=1:length(endIndex)-1
59 if(endIndex(n)~=startIndex(n+1)-1)
60 add = text(endIndex(n):startIndex(n+1)-1);
61 text_wo = [text_wo add];
64 text = [text_wo text(endIndex(n+1):end)];
65 %% extract constructor
66 [~,endIndex] = regexp(text,['function[a-zA-Z0-9\[\]\,\;\=\s]*' moduleName '.*?)']);
67 text=text(endIndex:end);
68 words={
'for',
'while',
'switch',
'try',
'if',
'parfor'};
69 % very ugly implementation since counter is not functional
70 % it depends on text which isnt a passed variable (but it works)
71 counter = @(word) length(regexp(text,[
'<' word
'>']));
72 count=sum(cellfun(counter,words));
73 endPos = regexp(text,
'<end>');
74 constructor_text=text(1:endPos(count+1));
75 %% look
for units/modules
76 [~,names]=regexp(constructor_text,
'=\s([a-zA-Z]+_v\d)\(',
'match',
'tokens');
82 if(length(tree{ii})>1)
84 elseif(length(tree{ii})==1)
85 props=[props; properties(cat(1,tree{ii}{1}))];
Superclass: basic building block to hold functions.
function getInternalUnits(in moduleName)
Gather all units/modules within a modules constructor.
function paramDeepCopy(in class, in param)
Copy parameters aligned to the properties of a module/unit.
function robolog(in msg, in varargin)
This function allows the user to print log messages in a standard way.
function getInternalUnitsNested(in moduleName)
Gather all units within a module as tree structure of cell arrays.
function getUnitsTreeProperties(in tree)
Gather all properties from a tree structure of units.
Superclass: collection/sequence of unit.