How to write variables from Matlab Function Block to the Simulation Data Inspector

2 次查看(过去 30 天)
Hi,
I am logging the signals I am measuring via the SDI to the workspace to do some postprocessing in the stop function callback of my simulation.
As I am also using many function blocks I would like to log variables in the function blocks programatically to the SDI. I did not find another way than creating an output port in the function block for a struct with all my measurement variables and define a bus for this output that demuxes the data outside the matlab function block so I can log the signals with the SDI.
To make things even worse, some of the function blocks are in a library and do have serveral instances.
Is there any smarter solution than using a bus? Also, using the bus means I do have to maintain the bus every time I am changing the content of my output struct of the measurement variables.
Thanks!!!

回答(1 个)

vidyesh
vidyesh 2023-11-2
Hi Jochen,
I understand that you are looking for a way to log variables in function blocks to the Simulink Data Inspector.
In addition to the method that has been discussed, another approach to log variables from function blocks in Simulink is by using global variables in the MATLAB Function blocks. This method involves referencing globally defined data within the function code.
You can find detailed information on how to accomplish this in the "Using Global Data with the MATLAB Function Block" section of the Simulink documentation:
In that documentation, you will find an example called "Retrieve Data From Data Store Memory Blocks" that demonstrates how to log a variable from a MATLAB function block.
In the above example, to enable logging of the variable, you can open the Block Parameters of the "Data Store Memory" block, go to the "logging" tab, and enable the "log data store data" option.
I hope this explanation clarifies the process for you.

类别

Help CenterFile Exchange 中查找有关 Prepare Model Inputs and Outputs 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by