Matsim
Matlab/Simulink interface. Easily create Simulink models from a Matlab script.
Install / Use
/learn @gave92/MatsimREADME
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.
Key features
- 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)
| Source script (.m) | Resulting model | Notes |
:-------------------------:|:-------------------------:|:-------------------------:
c = Constant(1) | <img src="https://github.com/gave92/matsim/blob/master/docs/images/readme/readme_1.PNG?raw=true" height="80" /> | Create a Constant block with value 1
res = a+b | <img src="https://github.com/gave92/matsim/blob/master/docs/images/readme/readme_2.PNG?raw=true" height="80" /> | Create an Add block and connect its inputs to blocks a and b
res = [a,b] | <img src="https://github.com/gave92/matsim/blob/master/docs/images/readme/readme_3.PNG?raw=true" height="80" /> | Create an Mux block and connect its inputs to blocks a and b
res = Max(a,b) | <img src="https://github.com/gave92/matsim/blob/master/docs/images/readme/readme_4.PNG?raw=true" height="80" /> | Create an MinMax block and connect its inputs to blocks a and b
res = 1 - u1./(u2.*u3) | <img src="https://github.com/gave92/matsim/blob/master/docs/images/readme/readme_5.PNG?raw=true" height="80" /> | Create a group of simulink blocks that computes a complex expression
Scope(Gain(FromWorkspace('var'),'Gain',0.5)) | <img src="https://github.com/gave92/matsim/blob/master/docs/images/readme/readme_6.PNG?raw=true" width="150" /> | Easily combine blocks
Installation
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 guide
Quick example to get started. For more check the tests folder.
1. Create or load a simulink model
import matsim.library.* % Import Matsim package
sys = simulation.load('my_model'); % Create or load a model named 'my_model'
sys.setSolver('Ts',0.01,'DiscreteOnly',true) % Set solver for the model
sys.clear() % Delete all blocks
sys.show() % Show the model
2. Create blocks
Vx = FromWorkspace('V_x'); % Add FromWorkspace and Constant blocks
Wr = FromWorkspace('W_r');
Rr = Constant(0.32);
slip = 1 - Vx./(Wr.*Rr); % Evaluate complex mathematical expression
sys.log(slip,'name','slip') % Log the output of the "slip" block
s = Scope(slip); % Create and open scope block
s.open()
3. Connect and layout the model
sys.layout() % Connect and layout the model
4. Simulate the system
V_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('StopTime',10).Logs; % Simulate the system
© Copyright 2017 - 2019 by Marco Gavelli
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
