how to obtain data on simulink model signal line and output ports in real time When simulink model is running?

3 views (last 30 days)
When I run a simulink model, I can get all the model data in the workspace, such as a variable named out. This is not real-time.
As shown in the following model, I want to obtain data on signal line and output ports in real time When simulink model is running.
These data are used in another m files in real time. Is there any way?

Answers (1)

Nithin
Nithin on 27 Feb 2025 at 9:43
There are several ways to accomplish this, depending on your final objective and implementation.
Refer to different methods below that can be considered to achieve this:
  • A "MATLAB Function" block can be used within the Simulink mode l to call custom MATLAB code that processes or logs data in real-time. This method is suitable if you intend to process data individually without needing its history.
  • The "To Workspace" block can log data with a limited buffer size, enabling near-real-time access. You can specify the buffer size with the "Limit data points to last" parameter and adjust the capture rate using the "Decimation" parameter. This method is ideal for processing data in chunks, though it may not be suitable for high-frequency logging.
  • If the goal is to process all the data in real time with a flexibility to choose the data grouping, the "UDP" or "TCP" blocks can be used in Simulink to send data to an external application or script in real-time. This requires setting up a server-client architecture. Refer to the following MATLAB answer to understand the process of sending data from Simulink to MALTAB: https://www.mathworks.com/matlabcentral/answers/1949113-how-to-send-data-from-simulink-using-the-udp-send-block-and-receive-the-data-in-matlab
For more information, kindly refer to the following MathWorks documentation.
I hope this helps in resolving your issue.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!