diff --git a/code/classes/SCDclass_algo.m b/code/classes/SCDclass_algo.m index c0f720bd4def55d30d4a44ada344eb160a3c0bc5..c00a0016667f9284060e83a4464325ac17bff148 100644 --- a/code/classes/SCDclass_algo.m +++ b/code/classes/SCDclass_algo.m @@ -239,14 +239,28 @@ classdef SCDclass_algo function callinits(obj) - if(~isempty(obj.stdinits)) - for(ii=1:numel(obj.stdinits)) + % call initialization functions that set fixed parameters + if ~isempty(obj.stdinits) + for ii=1:numel(obj.stdinits) - fprintf('Calling init function ''%s'', assigning its output to ''%s'' ...\n',char(obj.stdinits{ii}{1}),char(obj.stdinits{ii}{2})); - initcmd=sprintf('[fp]=%s(obj);', char(obj.stdinits{ii}{1})); - eval(initcmd); - Simulink.data.assigninGlobal(obj.modelname, char(obj.stdinits{ii}{2}), fp); - + initfunction = obj.stdinits{ii}{1}; + targetname = obj.stdinits{ii}{2}; + + fprintf('Calling init function ''%s'', assigning its output to ''%s'' ...\n',... + char(initfunction),char(targetname)); + + if ischar(initfunction) + initcmd=sprintf('%s(obj);', initfunction); + value = eval(initcmd); + elseif isa(initfunction,'function_handle') + value = initfunction(obj); % call function handle directly + else + error('initfunction must be a string or a function handle') + end + + % assigns in base workspace or datadictionary depending + % on where the target variable is + Simulink.data.assigninGlobal(obj.modelname, targetname, value); end end end