how to run simulink simulation from matlab script

 채택된 답변

User_in_Gim
User_in_Gim 2017년 3월 16일
Hi,
You can use sim command line to simulate your model : doc sim.
sim('Model_Name',Simulation_Time) % most basic way to simulate with command script.

댓글 수: 7

thank u very much my friend , u really helped . keep up the good work !!!
Thank you so much.
Thanks, this is a helpful tip.
If you're calling the sim function in a script, you probably want to assign the result to an output argument so you can access the simulation results.
out = sim(mdl);
give cod
Does the simulink model need to be open if we use this way?
If the model is not open, then the sim function automatically loads the model. Loading the model does not open the Simulink Editor. If you want to view the contents of the model in the Simulink Editor, you need to open the model by opening the file manually or by calling the open_system function.
The sim function does not close models that it loads automatically. The model remains loaded in memory until you close it (for example by calling the close_system function or issuing the command bdclose all) or until you end the MATLAB session.

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

추가 답변 (3개)

Reid Spence
Reid Spence 2024년 1월 22일
편집: Reid Spence 2024년 1월 22일
A prefered way to run a simulation from MATLAB is to use the SimulationInput object.
simIn = Simulink.SimulationInput("Model_Name"); %create object
simIn = simIn.setVariable("my_Parameter",2); %example of setting a parameter override
out = sim(simIn); %run simulation, all results returned in "out"
The benifits of using the SimulationInput object over using ">sim("model_name")" include:
  • ability to override parameters and settings without dirtying the model
  • a helpful container for all run specific overrides
  • easier transitions to other workflows such as parallel simulation with parsim or deployment with Simulink Compiler
marcus sick
marcus sick 2024년 3월 13일

0 개 추천

A recommended approach for executing simulations in MATLAB involves leveraging the SimulationInput object.
simIn = Simulink.SimulationInput("Model_Name i.e (YT3converter)"); % Create object simIn = simIn.setVariable("my_Parameter", 2); % Example of setting a parameter override out = sim(simIn); % Run simulation; all results are returned in "out"
The advantages of utilizing the SimulationInput object over the conventional method ">sim("model_name")" are manifold:
  • It enables parameter and setting overrides without modifying the model directly, ensuring model cleanliness and preserving its integrity.
  • Serving as a convenient container, it organizes all simulation-specific overrides, enhancing clarity and manageability.
  • Facilitates seamless transitions to alternative workflows like parallel simulation with parsim or deployment via Simulink Compiler, thus fostering versatility and adaptability in simulation practices.

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

질문:

2017년 3월 16일

댓글:

2025년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by