Coder Social home page Coder Social logo

kuan-li / matsim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gave92/matsim

0.0 1.0 0.0 1.36 MB

Matlab/Simulink interface. Easily create Simulink models from a Matlab script.

Home Page: https://it.mathworks.com/matlabcentral/fileexchange/68436-matsim

License: MIT License

MATLAB 99.87% Batchfile 0.13%

matsim's Introduction

Matsim

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.

logo donate

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) Create a Constant block with value 1
res = a+b Create an Add block and connect its inputs to blocks a and b
res = [a,b] Create an Mux block and connect its inputs to blocks a and b
res = Max(a,b) Create an MinMax block and connect its inputs to blocks a and b
res = 1 - u1./(u2.*u3) Create a group of simulink blocks that computes a complex expression
Scope(Gain(FromWorkspace('var'),'value',0.5)) Easily combine blocks

Installation

The automatic layout feature relies on GraphViz, which you need to install separately.

  1. Install GraphViz and add it to the system PATH
  2. Download and extract the Matsim package (from File Exhange or from here)
  3. 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

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,'slip')                          % Log the output of the "slip" block

s = Scope(slip);                              % Create and open scope block
s.open()

3. Connect and layout the model

simlayout(sys.handle)                         % 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('tstop',10).Logs;            % Simulate the system

Known issues

The 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

matsim's People

Contributors

gave92 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.