A sleek, intuitive interface for building Simulink models from a Matlab script.
Explore Matsim docs »
Report bug · Request feature
Matsim is a high level interface to create Simulink models from a Matlab script. Matsim is a wrapper around the standard simulink API that makes building a simulink model programmatically much faster.
- Automatic layout (no need to specify block positions!)
- Intuitive interface (you can "add", "subtract", "multiply", ... simulink blocks)
- Extensible library (easily add new blocks from your custom libraries)
The automatic layout feature relies on GraphViz, which you need to install separately.
- Install GraphViz and add it to the system PATH
- Download and extract the Matsim package (from File Exhange or from here)
- Add Matsim folder (and subfolders) to the Matlab path
Quick example to get started. For more check the tests folder.
sys =simulation.load('my_model'); % Create or load a model named 'my_model'sys.setSolver('Ts',0.01,'DiscreteOnly',true) % Set solver for the modelsys.clear() % Delete all blockssys.show() % Show the modelVx = FromWorkspace('V_x'); % Add FromWorkspace and Constant blocks Wr = FromWorkspace('W_r'); Rr = Constant(0.32); slip =1-Vx./(Wr.*Rr); % Evaluate complex mathematical expressionsys.log(slip,'slip') % Log the output of the "slip" block s = Scope(slip); % Create and open scope blocks.open()simlayout(sys.handle) % Connect and layout the modelV_x = [0:0.1:10;linspace(5,20,101)]'; % Define input variables W_r = [0:0.1:10;linspace(5,23,101)/0.32]'; simOut =sys.run('tstop',10).Logs; % Simulate the systemThe first time you execute a script you might get this error:
Attempt to modify 'simulink' which is a locked (read-only) library
Keep calm and execute the script again.
© Copyright 2017 - 2018 by Marco Gavelli
