Simulink Onramp — review, focus on tips and tricks

Vignesh balaji
3 min readSep 27, 2023

--

The best way to brush up and increase any known skill is to do a quick short examples to get up to the speed of natural thinking in them. Recently, I started using Simulink after sometime and hence I used Simulink Onramp tutorials from MATLAB. I am listing down the important tricks and trips while using Simulink. In a way, this is article is a reminder notes / repository for me too to look at it later.

What is Simulink ?

It is a graphical programming environment to build models of dynamic systems (systems varying with time) and analyze them. It is built ontop of MATLAB. It is a time based simulation environment.

General note -

  1. Simulink Blocks — Simulink has specific elements called blocks. Each block performs a specific operation on inputs and returns an output/outputs. This is very similar to a function block in a text based code. Having a thought about this will make you write a modular and scalable simulink model.
  2. Modelling equations — Since you are modelling a dynamic system. You will be either writting a model for a differential equation (continuous time system) or difference equation (discrete time system). So writting a equation as a model equires two thing taking care of equality sign (done by looping back the signal) and setting initial condition (done by setting an initial value of the looped back signal — to remove algebric loop). Example :- X[K] = X[k-1] + C
Figuring showing simulink model of an equation, X[K] = X[k-1] + C

It is seen that X_K signal is looped back to get new values of X_k and to represent the “=” sign of the equation. On top of that inside 1/Z block the intial value is set for X_K[0] else there won’t be any signal to start the model (will throw error). This is by principle of a differential equation in a dynamic system that it only integrates the equation for a small time step (which means it requires previous states called as initial conditons and also time).

Important take aways learnt in this Onramp -

I am only mentioning the tips and tricks, useful for people already know simulink.

Easy tips -

  1. Use Double click — Quick search bar to add any block in library (note, as many similar block are there in many libraries please know the source of the block you want)
  2. Right mouse click and hold on signal arrows — to drag signal lines to connect.
  3. Debugging blocks , Display (just text/numeric values) and Scope (plots continuously varying value)
  4. Double click to go inside a block
  5. Double click on signal to write the name of the signal
  6. F5 or ctrl+T for model run shortcut, ctrl+i to rotate a block (List of all shortcuts — https://nl.mathworks.com/help/simulink/ug/summary-of-mouse-and-keyboard-actions.html)

Important tips -

  1. You can create and use variables bidirectionally between MATLAB and Simulink (note use Base workspace as location for this), Note - simulink can create MATLAB variables too.
  2. You can use MATLAB functions inside simulink. This is used to incorporate existing MATLAB code or write new ones. y is output and u is input by default for this block. Changing the number of y and u (eg:-y1, y2, y3) will automatically add ports in the block.
  3. Since Simulink is a time based simulation, While implementing a discrete time simulation use Debug->Information Overlays -> Sample time (colour/ text/ time legend etc) to see different sample times in the system. Else you can assume the system as continuous if the sampling time is infinitissimal :)

These are just few basic tips and tricks. Any programming (including graphical programming in simulink) require decision statement. This tutorial says using swutch case blocks. More complex decision making process can be done using stateflow. To learn different design patterns and hierarchy in simulink use this link https://nl.mathworks.com/help/simulink/gs/navigate-model.html .

References -

  1. Simulink Onramp — https://matlabacademy.mathworks.com/details/simulink-onramp/simulink
  2. Simulink wiki — https://en.wikipedia.org/wiki/Simulink
  3. Simulink Model hierarchy — https://nl.mathworks.com/help/simulink/gs/navigate-model.html
  4. Stateflow — https://nl.mathworks.com/help/stateflow/getting-started.html

--

--