Use Simulink PreSimFcn to set metadata in a Simulink.SimulationOutput object
4 ビュー (過去 30 日間)
古いコメントを表示
Is it possible to store variables from a simulation's PreSimFcn in the Simulink.SimulationOutput object's metadata?
I am setting up my Simulink.SimulationInput objects as:
for casenumber = 1:no_of_cases_to_run
inputs = {'Arg1','Arg2','ArgN','casenumber'};
simIn(casenumber) = Simulink.SimulationInput(model);
for iArg = 1:length(BD29Inputs)
eval(['simIn(casenumber) = simIn(casenumber).setVariable(''',inputs{iArg},''',',inputs{iArg},')'])
end
% Use a temporary variable for the SimIn element to avoid runaway memory usage when using a preSimFcn with parsim
tmpSimIn = simIn(casenumber);
% Set PreSimFcn to setParSimBaseWorskpaceVariables, which runs the function required to be run in parallel
simIn(casenumber) = simIn(casenumber).setPreSimFcn(@(x) setParSimBaseWorkspaceVariables(tmpSimIn));
end
simOut = parsim(simIn);
My PreSimFcn is
function setParSimBaseWorkspaceVariables(simIn)
% Assign variables required by the IPTOS_BD29_Simulation function
% to the function's workspace
varList = {'Arg1','Arg2','ArgN','casenumber'};
nVarsAssigned = 0;
for iVar = 1:length(simIn.Variables)
if nVarsAssigned == length(varList)
break
elseif ~isempty(find(strcmp(simIn.Variables(iVar).Name,varList), 1))
eval(strcat(simIn.Variables(iVar).Name,'=simIn.Variables(iVar).Value;'));
nVarsAssigned = nVarsAssigned + 1;
end
end
% Run the function required to be run in parallel
funcOutput=func(Arg1,Arg2,ArgN);
% Save funcOut
save(fullfile(iptos_output_file_directory,['Results_',num2str(casenumber),'.mat']),'funcOutput')
% Need help here - how to store 'funcOutput' as metadata in simOut
setUserData(simOut,funcOutput)
end
0 件のコメント
回答 (1 件)
Paul
2023 年 5 月 16 日
Hi Afzal,
You can store data into the Simulink.SimulationOutput object via the SimPostFcn. Here is an example.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Run Multiple Simulations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!