Nick
Nick

Reputation: 2980

Read simulink signal data into matlab during simulation

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?

Upvotes: 0

Views: 2942

Answers (2)

Akanksha
Akanksha

Reputation: 96

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

Upvotes: 0

Captain Future
Captain Future

Reputation: 339

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.

Upvotes: 1

Related Questions