Clear Filters
Clear Filters

What is the best way to log Simulink signals into a dedicated appdesigner-based MATLAB GUI ?

3 views (last 30 days)
Hi,
I am trying to build a dedicated GUI to display signals of a running Simulink model in real-time.
To do this, I saved my signals in a mat-file using the "to file" block of Simulink.
These signals are then periodically retrieved and updated by my GUI using timers (Schedule execution of MATLAB commands - MATLAB - MathWorks France) and the "matfile()" function (Access and change variables in MAT-file without loading file into memory - MATLAB - MathWorks France).
The problem I am facing is that my GUI cannot always properly read the signals stored in the .mat file generated by Simulink, probably because they are being written by said Simulink at the same time.
I partially solved the problem by wrapping my "updateGraph()" function, which is called by my timers, in a try/catch statement.
However, this solution does not work really well since I still get some warnings when my timers try to read the mat-files.
In addition, my retrieved signals are sometimes "corrupted", in the sense that they all become equal to 0: this happens when I try to load the data of my mat-file while it is being written by simulink.
I recently saw in this post (How do I update a GUI designed in App Designer with data from a running Simulink model? - MATLAB Answers - MATLAB Central) that you can use event listeners and runtime objects to achieve my goal.
However, I would like to be able to close and re-open my GUI without losing the whole signal history, which is why I would like to stick with mat-files rather than runtime objects if possible.
Does anyone know how to solve mat-file read/write conflicts between Simulink and MATLAB ?
I am also open to improvements if you think what I am doing makes no sense.
Thank you all in advance for your help.
Guillaume.
  1 Comment
Brahmadev
Brahmadev on 2 Apr 2024
One idea that can be worth trying is: Using the runtime objects to read the Simulink signals and then updating the GUI from them. And periodically save the data from App Designer into a MAT-file (instead of using the To File block). This will let us preserve the data between different simulation runs. For reading the previous data after closing and re-opening the GUI, a callback can be implemented to read the previous simulation signal history on start-up. This should remove the read/write conflict.
If this doesn't solve your issue, a model that helps us recreate the issue would be helpful.
Hope this helps!

Sign in to comment.

Answers (0)

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!