Can I use Simulink.SimulationInput to manage DataLogging for Outports

3 views (last 30 days)
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
Mats Widmark
Mats Widmark on 28 Mar 2024
Hi,
Yes if you work on the DataLoggingOverride directly, the model is modified, but I'm creating a
Simulink.SimulationInput object, and apply changes with e.g. obj.setModelParameter. Then the modifications are applied only locally in the object, and not in a global sense. See below:
si = Simulink.SimulationInput('sldemo_mdlref_bus');
% Run without modifications
out = si.sim()
>> out.topOut
ans =
Simulink.SimulationData.Dataset 'topOut' with 4 elements
Name BlockPath
____________ ________________________________________
1 [1x1 Signal] COUNTERBUS sldemo_mdlref_bus/Concatenate
2 [1x1 Signal] OUTERDATA sldemo_mdlref_bus/CounterA
3 [1x1 Signal] INCREMENTBUS sldemo_mdlref_bus/IncrementBusCreator
4 [1x1 Signal] INNERDATA ...erA|sldemo_mdlref_counter_bus/COUNTER
% Run with modifications
mdlInfo = Simulink.SimulationData.ModelLoggingInfo.createFromModel('sldemo_mdlref_bus');
mdlInfo.Signals = mdlInfo.Signals(1:3); % Remove fourth and last signal from logging list
si = si.setModelParameter('DataLoggingOverride', mdlInfo); % Modify object.
out2 = si.sim();
>> out2.topOut
ans =
Simulink.SimulationData.Dataset 'topOut' with 3 elements
Name BlockPath
____________ _____________________________________
1 [1x1 Signal] COUNTERBUS sldemo_mdlref_bus/Concatenate
2 [1x1 Signal] OUTERDATA sldemo_mdlref_bus/CounterA
3 [1x1 Signal] INCREMENTBUS sldemo_mdlref_bus/IncrementBusCreator
So this would have worked perfectly for my purposes, if you only could add signals as well as remove.
To "turn on all signals of possible interest" is not an attractive option for me since I run big structures of models and everything could be of potential interest at some point.
Paul
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.

Sign in to comment.

Answers (1)

Rasmita
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
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.
Mats Widmark
Mats Widmark on 22 Mar 2024
Edited: Mats Widmark on 22 Mar 2024
Hi again, it took time before I had the time to look at it again.
However, the approach above did not work straight away.
I tried this:
===================
blockHandle = get_param('SimulinkCtrlTestModel/InputBus', 'handle');
dataLoggingProperties = struct('DataLogging', {'on'});
Simulink.BlockDiagram.modifyTunableParameters(blockHandle, dataLoggingProperties);
Error using modifyRTP
The rtp structure passed in was not valid: the rtp must be a struct with a field named "parameters".
Error in modifyRTP
Error in sl_feval
Error in modifyBDTunableParametersImpl
Error in slprivate
Error in Simulink.BlockDiagram.modifyTunableParameters
===================
Firstly, the handle that has a property DataLogging is the outport handle, so I tried to address this instead:
===================
portHandle = get(blockHandle, 'PortHandles');
Simulink.BlockDiagram.modifyTunableParameters(portHandle.Outport, dataLoggingProperties);
<Same error as above.>
===================
Secondly, the method Simulink.BlockDiagram.modifyTunableParameters is applicable only to accelerator models?
I manage to create an rtp object by
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(SimulinkCtrlTestModel)
but I'm not sure what to do with it.
Thirdly, I tried the DataLoggingOverride parameter to control logging of signals. I managed to apply overrides, but realized that the only override possible is to remove logging signals marked for logging, not add arbitrary signals in the model for logging? If so, this is not very helpful.

Sign in to comment.

Categories

Find more on Save Run-Time Data from Simulation in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!