MATLAB: How to set the ‘Datalogging’ property for individual signals in the model from the command line in Simulink

datadataloggingindividualloggingmodelselectedsimulink

I would like to set the 'Datalogging' property of individual selected signals from the command line.

Best Answer

To set the individual signal 'DataLogging' property you will need to find the line in the model corresponding to the selected signal. Then the 'DataLogging' property in the 'Srcport' object of the line needs to be set. If the model in question is the current model, and the name of the signal is 'DesiredSignal', the following code will set the 'DataLogging' property to 'on':
% First, find all of the lines in the system
Sig_handle = find_system(gcs, 'FindAll', 'on', 'type', 'line','Name','DesiredSignal');
Srcport_handle = get_param(Sig_handle,'SrcPortHandle');
set_param(Srcport_handle,'DataLogging','on');