How can I disable signal logging across an entire Simulink model?

29 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 27 Sep 2024
Modifié(e) : MathWorks Support Team le 9 Oct 2024
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:
  • 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.
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.

Plus de réponses (0)

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by