Azzera filtri
Azzera filtri

how to run simulink simulation from matlab script

1.071 visualizzazioni (ultimi 30 giorni)
hello i need to run simulink simulation from matlab, how to do it using matlab command in script ?

Risposta accettata

User_in_Gim
User_in_Gim il 16 Mar 2017
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.
  5 Commenti
Sara Nadeau
Sara Nadeau il 19 Apr 2023
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);

Accedi per commentare.

Più risposte (3)

Reid Spence
Reid Spence il 22 Gen 2024
Modificato: Reid Spence il 22 Gen 2024
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

Guy Rouleau
Guy Rouleau il 9 Lug 2024 alle 18:49

marcus sick
marcus sick il 13 Mar 2024
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.

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by