Assigning Model Simulation parameters programmatically

조회 수: 8 (최근 30일)
Omkar
Omkar 2023년 7월 6일
댓글: Omkar 2023년 7월 6일
I am trying to simulate a simulink model, where I want to have different Solver Step Sizes (Fixed) and simulation durations (start/stop time) for different simulations, and it would be helpful if the same could be done using a matlab code.
Following are the matlab arrays for various simulations:
simTime = [10 20 40 60 100]
stepSize = [1e-6 2e-6 4e-6 6e-6 10e-6]
It would be really helpful, if someone can provide an easy way for the above using the sim function, thanks!

채택된 답변

Rahul
Rahul 2023년 7월 6일
Hey Omkar,
Assuming that you are using the latest release r2023a and that your specified parameter values are in seconds, you can specify parameter names as well as their string values in the sim function in input arguments, using the num2str function, as follows:
simTime = [10 20 40 60 100];
stepSize = [1e-6 2e-6 4e-6 6e-6 10e-6];
% Size of simulation parameter array
elements = numel(simTime);
for idx = 1:elements
% Insert actual model name instead of 'modelName'
sim('modelName', 'StartTime', '0', 'StopTime', num2str(simTime(idx)), 'FixedStep', num2str(stepSize(idx)));
end
For reference, you can check out the sim function documentation or even right-click any parameter in the Solver Setting under Model Settings, and get a what's this' pop-up to know more about interacting with the parameter.
Hope that helps!
  댓글 수: 1
Omkar
Omkar 2023년 7월 6일
Thanks, that works but what if I want to have time step value set to auto for some cases?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by