MATLAB: How to control the signal logging of individual signals from the command line in Simulink

simulink

I would like to turn on data logging for a particular signal using command line commands.

Best Answer

In order to turn logging on for a particular signal, you would have to set the "DataLogging" property of the port outputting this signal to "on". For example, assume that you want to turn logging on for a signal that is ouput by a block called "myblock" in the model "mymodel". The following example code achieves this.
bH = get_param('mymodel/myblock','handle');
ports = get_param(bH, 'PortHandles');
pH = ports.Outport;
set_param(pH, 'DataLogging','on')
set_param(pH,'Name','mysignal')