“How can I write two M‑scripts: one to disable signal logging across the whole Simulink model (masked subsystems), and another to enable logging only for selected signals

15 visualizaciones (últimos 30 días)
I’ve developed a script that successfully disables all logged signals in a Simulink model when it's used in a standard configuration. However, I’m facing an issue when applying the same script to the exact same model after it has been placed inside a masked subsystem. In this masked context, the script no longer disables the logged signals as expected. This behavior also applies to signal logging operations in general. Could you please help me understand why this is happening and guide me on how to resolve it?
Script :
% %% Disable all signal logging in the given Simulink model
% %% Model
modelPath = '***'; % Update with your actual path
addpath(fileparts(modelPath));
load_system(model);
model = '***';
% %% Load the model if not already loaded
if ~bdIsLoaded(model)
load_system(model);
end
% %% Turn off model-level logging
set_param(model, 'SignalLogging', 'off');
set_param(model, 'SaveOutput', 'off');
set_param(model, 'SaveState', 'off');
% %% Turn off DataLogging on all ports and lines, including variants
ports = find_system(model, 'MatchFilter', @Simulink.match.allVariants,'FindAll', 'on','Type', 'Port');
lines = find_system(model, 'FindAll', 'on', 'MatchFilter', @Simulink.match.allVariants, 'Type', 'Line');
for i = 1:length(ports)
try
set_param(ports(i), 'DataLogging', 'off');
catch
% Some ports may not support DataLogging
end
end
for i = 1:length(lines)
try
set_param(lines(i), 'DataLogging', 'off');
catch
% Some lines may not support DataLogging
end
end
% %% Unmark all signals for SDI streaming
try
Simulink.sdi.clear;
Simulink.sdi.setStreaming(false);
Simulink.sdi.setAutoSave(false);
Simulink.sdi.setRecordData(false);
catch
% Ignore if SDI is not available
end
% %% Disable logging for all blocks including variants
blocks = find_system(model, ...
'FollowLinks', 'on', ...
'LookUnderMasks', 'all', ...
'MatchFilter', @Simulink.match.allVariants);
for i = 1:length(blocks)
try
set_param(blocks{i}, 'DataLogging', 'off');
catch
% Some blocks may not have DataLogging parameter
end
end
fprintf('✅ All signal logging disabled for model: %s\n', model);

Respuestas (1)

Mark McBroom
Mark McBroom el 3 de Oct. de 2025 a las 0:53
Your first 2 find_system() calls don't look under masks. Try adding 'LookUnderMasks','all'

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by