Use Simulink PreSimFcn to set metadata in a Simulink.S​imulationO​utput object

4 ビュー (過去 30 日間)
Afzal
Afzal 2023 年 5 月 16 日
回答済み: Paul 2023 年 5 月 16 日
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

回答 (1 件)

Paul
Paul 2023 年 5 月 16 日
Hi Afzal,
You can store data into the Simulink.S​imulationO​utput object via the SimPostFcn. Here is an example.

カテゴリ

Help Center および File ExchangeRun Multiple Simulations についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by