MATLAB Answers

Is it possible to read the value of a Simulink signal passing through a signal line from the MATLAB command line?

133 views (last 30 days)
I would like to read the value of a Simulink signal passing through a signal line from the MATLAB command line.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Nov 2016
This feature has been added in Simulink 6.0 (R14). See the following section of the Simulink documentation:
Accessing Block Data During Simulation :: Working with Blocks (Using Simulink):
For example, to access the output data from a particular block during simulation, perform the following steps:
1) Set the simulation stop time to 'Inf'
2) Start the simulation
3) Click on the block you want to access
4) Type the following at the MATLAB Command Line:
rto = get_param(gcb,'RunTimeObject');
If you are using a previous version, see the following:
The ability to do read the value of a signal from the MATLAB command line during a simulation is not available in Simulink.
To work around this issue, you can write a MATLAB file S-Function to send data to the MATLAB workspace during the simulation. For more information, see the following Related Solution "How do I log a signal from my Simulink model to the MATLAB workspace at each simulation time step?"

  1 Comment

Suvrat Ramasubramanian
Suvrat Ramasubramanian on 6 Mar 2020
I am trying to read the signal data from the outport of a simulink block from python. I ran the following command:
import matlab.engine
eng = matlab.egine.start_matlab()
eng.set_param('model','SimulationCommand','start',nargout = 0)
rto = eng.get_param('model/subsystem','RunTimeObject')
data = eng.get(rto.Outport(1))
But during the execution the python script runs the last two line after the simulation ends and generates an error
rto = eng.get_param('model/subsystem','RunTimeObject')
File "C:\Python27\lib\site-packages\matlab\engine\", line 84, in __call___stderr).result()
File "C:\Python27\lib\site-packages\matlab\engine\", line 106, in result self._future,self._nargout, None, out=self._out, err=self._err)
TypeError: unsupported data type returned from MATLAB
Is there a way to start reading the data at the beginning of simulation till the end?

Sign in to comment.

More Answers (0)

Sign in to answer this question.