How to input the sample time of model (.slx file) from a .m file?

3 次查看(过去 30 天)
Hello, I want to integrate the model and the .m file together such that I don't have to open the model file to make the necessary changes. The only two parameters I need to change are Simulation end time and Sample time. While I have found a way to edit simulation end time using the sim('model', [0 sim_end]) command, I cant seem to find the way to control the sample time (powergui/configure parameters/solver/simulation type: discrete/sample time). Please help
  1 个评论
Varun Jadhav
Varun Jadhav 2015-10-28
I found a way, putting the sampling time in the script and defining it with a variable, & putting that variable name in the "Sample Time" space. But is there a way to choose the simulation type (discrete/continuous) and solvers (TBE/Tustin/Backward Euler)?

请先登录,再进行评论。

采纳的回答

Sebastian Castro
Sebastian Castro 2015-10-28
Yes, this is possible using the set_param function. Note that the powergui block changed in R2015a (I believe) to be more "Simulink-like", so I'm working off the latest version when I tried this out.
To change the model's stop time is a global model setting, so you can do something like:
>> modelName = 'myModel';
>> load_system(modelName);
>> set_param(modelName,'StopTime','50')
To change the powergui block properties, you have to use the block name. For example:
>> blockName = 'myModel/powergui'; % You can obtain this by selecting the block and typing gcb
>> set_param(blockName,'SimulationMode','Discrete')
>> set_param(blockName,'SolverType','Tustin/Backward Euler (TBE)')
>> set_param(blockName,'SampleTime','1e-6')
- Sebastian

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Electrical Block Libraries 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by