Simulink SImulation Inputs and Model Variables

5 次查看(过去 30 天)
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?

采纳的回答

Paul
Paul 2023-1-16
Instead of using the StopFcn, maybe you can use setPostSimFcn functionality
  7 个评论
Paul
Paul 2023-1-19
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 2023-1-22
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

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by