This application demonstrates how listeners can be attached to the blocks in a Simulink model, and how those listeners can be used to display block inputs and outputs on a MATLAB user interface. (The main function for achieving this is called add_exec_event_listener.)
The model can be executed either as a standard simulation or after being built into a generic real-time target (for those users with an RTW license). In the later case, RTW's External Mode and TCP/IP is used to transfer data from the running executable to the model and thence to the UI.
The use of listeners to view signals rather than the traditional approach of writing a custom S-Function block has at least 2 advantages: firstly the model is not "corrupted" by having to add any special viewing block (this is particularly advantageous if the model is also to be used with RTW); and secondly the same UI could be used to view signals from different models.
Specifically this application works with a simple model called 'simpleModel.mdl', that contains the three blocks
Sine Wave --> Gain --> Scope
The UI allows the model to be started and stopped, and allows the value of the gain to be tuned. The value of the signal being fed into the Scope block is displayed on an axis on the UI. The model does not have to be open to use the UI (and it's recommended for it to be closed).
The UI allows the model to be run in either simulation mode (requiring a Simulink license) or as a generic real-time (GRT) executable (since the model must be "built" this requires an RTW license).
It is intended as a demonstration program to show various aspects of using MATLAB, Simulink and RTW:
- how to create a MATLAB UI using command line functionality
- how to start/stop a Simulink model using command line functionality
- how to add a listener to a Simulink block so that signals can be viewed from a MATLAB UI.
- how to build a GRT executable using command line functionality
- how to interface with code running in "real-time" (For the purposes of this UI the grt code is running on the host machine, so it is not running in hard real-time, however it is using External Mode to communicate with the code and hence shows how communication would be performed if the code was truly running on an RTOS.
Phil Goddard (2021). Simulink Signal Viewing using Event Listeners and a MATLAB UI. (https://www.mathworks.com/matlabcentral/fileexchange/24294-simulink-signal-viewing-using-event-listeners-and-a-matlab-ui), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!