Access block output data from simulink in python

2 views (last 30 days)
Hi All,
I am trying to run a simulink model form python using matlab engine. I am able to load the model and data in the workspace and run the simulation. I would like to read the outputs of a subsytem block from the simulink model during simulation that I can then use in python.
I tried using the add_exec_event_listener function in the startFcn callback of the subsystem
blk = 'path/to/the/subsystem'
add_exec_event_listener(blk,'PostOutputs',@readsubsysdata)
where readsubsysdata.m is
function [data1] = readsubsysdata(block,~)
data1 = block.outport(1).data;
end
How do I read the data from the block in python during the simulation? I am not sure if I completely follow the steps of doing so.
Thanks in advance!

Answers (0)

Community Treasure Hunt

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

Start Hunting!