Simulink SImulation Inputs and Model Variables

5 vues (au cours des 30 derniers jours)
Florian Rössing
Florian Rössing le 16 Jan 2023
Commenté : Paul le 22 Jan 2023
I want to run a model for different input parameters, using an arraySimulink.SimulaitonInput Objects.
In the StopFcn of the Model I want to read some of the model parameters and variables set by the simulink.SimulationInput objects.
To access the parameters I can call
get_param(gcs,'Parameter')
to get the value of the parameter as set by the Simulink.SimulationInput object.
However to access variables of the model I would need to do:
mdlWks = get_param(gcs,'ModelWorkspace');
Variable = getVariable(mdlWks,'Variable');
This however only gives me the default version of the value for Variable. I waat the current set value of Variable though. Is there an alternative get_var function or something that can do this?

Réponse acceptée

Paul
Paul le 16 Jan 2023
Instead of using the StopFcn, maybe you can use setPostSimFcn functionality
  7 commentaires
Paul
Paul le 19 Jan 2023
Well, you could just as easily do that. But the original qeustion started with using using the StopFcn, so I thought you wanted to use automatic callback functionality. Either way, sounds like you have a path forward.
Paul
Paul le 22 Jan 2023
I just realized that the code I posted will overwrite output data in output of sim. The corrections would be pass the sim output into the post sim function, modify it, and return it.
simIn(ii) = setPostSimFcn(simIn(ii),@(simout) simpostfunc(out,simIn(ii).Variables));
function out = simpostfunc(out,simvariables)
% simple function to echo the simIn variables to the the simulation output
out.simvars = simvariables;
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Configure and View Diagnostics dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by