0
votes

I want to continuously read simulink signal data into the command line while the simulation is running. get_param() seems to be blocking so that doesn't quite work when put in an infinite while loop.

I'm now trying to use a UDP send block but I can't seem to receive data. My UDP block sends data to localhost over remote port 25000 and local port 25001.

In matlab I use the following code but it simply times out with no data

u=udp('127.0.0.1', 25001,'LocalPort',25000);
fopen(u)
fread(u)
fclose(u)
delete(u)

What are my options to continuously read out simulink signal data into Matlab CLI?

2
Are you wanting to do this for just "one or two" signals, or for potentially many signals? And are you wanting/needing the actual data in the MATLAB Workspace, or are you just wanting to display the data value in the Command Window (i.e. as part of a text message) rather than store it?Phil Goddard

2 Answers

0
votes

Control Simulation Using the "set_param()" command like follows:

set_param('sys','SimulationCommand','WriteDataLogs')

For a working example, type "sldemo_varsize_basic" in the matlab command window. Then above command becomes

set_param('sldemo_varsize_basic','SimulationCommand','WriteDataLogs')

If you set the simulation time to sufficiently large and start the simulation, the "simout, simout1", "tout" and "xout" variables are created/updated in the workspace every time you issue the command above.

Unfortunately, I was not able to find a good quality documentation of this feature.

0
votes

Are you trying to store the value of your model outports DURING simulation? This is not possible because the variables 'simout, simout1", "tout","xout" etc are created only once simulation is OVER.

In order to read/store the value of outports during simulation, you will have to attach an 'Runtime Object' to the outports. Refer 'Access Block Data During Simulation' in the Simulink documentation or see this link: http://in.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html?s_tid=gn_loc_drop

Hope it helps :)

This question has already been answered here using RunTime Objects as I have described above: https://stackoverflow.com/a/17006419/6580313