- Load Your Model: Ensure your model is loaded in MATLAB.
- Run the Script: Call the function "disableSignalLogging(<your_model_name>)" with the name of your top-level model in the MATLAB Command Window.
How can I disable signal logging across an entire Simulink model?
33 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2024 年 9 月 20 日
編集済み: MathWorks Support Team
2024 年 10 月 9 日
How can I disable signal logging across an entire Simulink model, including any library-linked sub-models or reference models? Additionally, how can I achieve this if the Simulink model contains reference and library models within variant subsystems?
採用された回答
MathWorks Support Team
2024 年 9 月 27 日
編集済み: MathWorks Support Team
2024 年 10 月 9 日
In MATLAB, while there's no single command to disable signal logging across the entire model, including any library-linked sub-models or reference models, you can achieve this with a script that iterates through all the blocks in the model hierarchy. Please refer to the general approach mentioned in the following MATLAB script:
function disableSignalLogging(modelName)
% Load the model if it is not already loaded
if ~bdIsLoaded(modelName)
load_system(modelName);
end
% Get all blocks in the model, including library links and referenced models
allBlocks = find_system(modelName, 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'Type', 'Block');
% Iterate through all blocks and disable signal logging
for i = 1:length(allBlocks)
try
% Disable signal logging for the current block
set_param(allBlocks{i}, 'DataLogging', 'off');
catch
% If the block does not support signal logging, continue
fprintf('Skipping block: %s\n', allBlocks{i});
end
end
% Save and close the model if necessary
save_system(modelName);
% close_system(modelName);
end
If the Simulink model contains reference and library models within variant subsystems, you need to traverse the active variant configurations and apply a similar logic recursively to ensure that all signal logging is disabled. Please refer to the example MATLAB script below for a general approach:
function disableSignalLogging(modelName)
% Load the model if it is not already loaded
if ~bdIsLoaded(modelName)
load_system(modelName);
end
% Disable signal logging recursively
disableLoggingRecursive(modelName);
% Save and close the model if necessary
save_system(modelName);
close_system(modelName);
end
function disableLoggingRecursive(systemName)
% Get all blocks in the system
allBlocks = find_system(systemName, 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'Type', 'Block');
for i = 1:length(allBlocks)
try
% Disable signal logging for the current block
set_param(allBlocks{i}, 'DataLogging', 'off');
catch
% If the block does not support signal logging, continue
fprintf('Skipping block: %s\n', allBlocks{i});
end
% Check if the block is a Variant Subsystem
if strcmp(get_param(allBlocks{i}, 'BlockType'), 'SubSystem') && ...
strcmp(get_param(allBlocks{i}, 'Variant'), 'on')
% Get the active variant choice
activeVariant = get_param(allBlocks{i}, 'VariantControl');
if ~isempty(activeVariant)
% Recurse into the active variant subsystem
disableLoggingRecursive(activeVariant);
end
end
% Check if the block is a Model Reference
if strcmp(get_param(allBlocks{i}, 'BlockType'), 'ModelReference')
% Get the referenced model name
refModelName = get_param(allBlocks{i}, 'ModelName');
% Recurse into the referenced model
disableLoggingRecursive(refModelName);
end
end
end
Usage Guidelines:
Please note that this script will affect all blocks that support signal logging, so use it cautiously if you need to maintain logging for specific blocks. If you have custom blocks or specific configurations, you may need to adjust the script accordingly.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Programmatic Model Editing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!