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

4 vues (au cours des 30 derniers jours)
Afzal
Afzal le 16 Mai 2023
Réponse apportée : Paul le 16 Mai 2023
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

Réponses (1)

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

Catégories

En savoir plus sur Run Multiple Simulations dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by