Python code link to simulink issue
Show older comments

Hi does anyone know why the blocks show color after running the simulation? and how to set this? I want to link this simulink to my python code. Any recommendations and reply will be appreciate.
7 Comments
Umar
on 2 Jul 2024
Hi Yeow,
To answer your questions, please see my comments below.
why the blocks show color after running the simulation? and how to set this?
These colors can signify different meanings such as:
Gray: Indicates an inactive or disabled block. Blue: Represents a block that is actively running or being simulated. Red: Indicates an error or warning state in the block. Green: Typically signifies a successfully executed block
Now, bear in mind that annotations themselves do not directly change block colors, they can provide additional context for understanding the block's purpose or behavior.To add an annotation to a block in Simulink, you can:
% Example: Adding an annotation to a block
annotation('textbox',[0.2 0.2 0.1 0.1],'String','Custom Annotation','Color','blue');
Question#2, I want to link this simulink to my python code, Any recommendations and reply
Try utilizing the MATLAB Engine API for Python, enabling communication between MATLAB and Python environments. This integration allows you to exchange data, call MATLAB functions from Python, and vice versa, facilitating a seamless connection between your Simulink model and Python code. For more information about it, please refer to
https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
Yeow Yu Leong
on 3 Jul 2024
Sam Chak
on 3 Jul 2024
From the signal flow and signal signs, the system is clearly unstable (to those who understand mass-spring-damper).
Since
and
are zero, the differential equations can be interpreted as:
If
and
are assigned, then differentiating Eq. (1) gives
and substituting Eq. (2) gives
Rearranging that to the standard Newton's form:
with acceleration on left-hand side and force on right-hand side gives
If you solve the 2nd-order differential equation analytically, you'll get

Sam Chak
on 3 Jul 2024
Those values are found by solving the quadratic equation:

Umar
on 3 Jul 2024
Hi @Sam Chak,
I do appreciate the teamwork to resolve this problem. You seem like a great guy. Happy 4th of July to you and your family. Also, making contributions by making difference in people lives which is the same goal I have.
Yeow Yu Leong
on 3 Jul 2024
Umar
on 3 Jul 2024
Glad to help out, Yeow, please let us know if you need further assistance.
Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!