Can I use Simulink.SimulationInput to manage DataLogging for Outports
3 views (last 30 days)
Show older comments
I have a large model that I want to turn on DataLogging only for signals of particular interest in a given simulation.
I am already using the Simulink.SimulationInput object to modify e.g. model workspace parameters, which is conventient because the original model stays the same.
However, the only way I have found to modify the DataLogging state of signals is to load the model, find a given Outport handle and do
>> set(outPortHandle, 'DataLogging', 'on');
The problem is that this puts the model into a modified state, and I can only close afterwards by force and discard other possible changes.
So in short I would like to use SimulationInput object to do something like
>> simIn.setBlockParameter('TopModel/Subsystem/Block.PortHandles.Outport(2)', 'DataLogging', 'on');
but the syntax only allows me to access the Block attributes on top level?
5 Comments
Paul
on 28 Mar 2024
Thanks for showing your method. I was using Simulink.SimulationInput with a set_param command in the PreSimFcn to turn off data logging for specified signal, and that was causing the model to become dirty.
Answers (1)
Rasmita
on 11 Apr 2023
Hi Mats,
It is my understanding that, you want to turn on 'DataLogging' only for signals of particular interest using 'SimulationInput' object. Unfortunately, it is not possible to set the 'DataLogging' state of a signal using the ‘setBlockParameter’ method of the ‘Simulink.SimulationInput‘ object. This is because the 'DataLogging' state is an attribute of the block port, not the block itself.
You can use the ‘Simulink.BlockDiagram.modifyTunableParameters’ function to modify the 'DataLogging' properties of the blocks corresponding to the signals of interest. Here is an example:
% Specify the paths to the signals you want to enable DataLogging for
signalPaths = {'myModel/Signal1', 'myModel/Signal2', 'myModel/Signal3'};
% Get the handles of the blocks corresponding to the signals of interest
blockHandles = cell(length(signalPaths), 1);
for i = 1:length(signalPaths)
blockHandles{i} = get_param(signalPaths{i}, 'Handle');
end
% Create a structure with the DataLogging properties to set for each block
dataLoggingProperties = struct('DataLogging', {'on'});
% Modify the DataLogging properties of the blocks using modifyTunableParameters
Simulink.BlockDiagram.modifyTunableParameters(blockHandles, dataLoggingProperties);
This approach modifies the 'DataLogging' properties of the blocks directly in the model but does not modify the original model itself. However, any changes made to the original model after running this code snippet may overwrite the 'DataLogging' properties set in this way.
For information, refer below documentation:
Hope this helps.
Regards,
Rasmita
3 Comments
Paul
on 11 Apr 2023
Is there a doc page for Simulink.BlockDiagram.modifyTunableParameters? I couldn't find it.
I did find it mentioned on Code Regeneration in Accelerated Models, but it was just plain text, not a link to doc page.
See Also
Categories
Find more on Save Run-Time Data from Simulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!