How to delete dublicate entries in logsout

3 views (last 30 days)
Max Wagenblast
Max Wagenblast on 16 Sep 2021
Answered: Pratik on 16 Apr 2024
I have unfortunately double logged some signals at different levels in simulink simulations. This leads to duplicate entries in the logsout. How can I easily delete duplicate entries?

Answers (1)

Pratik
Pratik on 16 Apr 2024
Hi Max,
As per my understanding, you have encountered an issue where some signals were logged multiple times, resulting in duplicate entries within the logsout object. Duplicate entries need to be identified and removed from logsout, ensuring that each signal is represented uniquely.
To remove duplicate entries from the logsout object in Simulink simulations, MATLAB scripting can be used to manipulate the 'Simulink.SimulationData.Dataset' object that logsout typically represents. The process involves iterating through the logsout object, identifying duplicates based on some criteria (like signal names), and then keeping only one instance of each duplicate. Please refer to the following MATLAB script:
% Assuming logsout is your Simulink.SimulationData.Dataset object
uniqueNames = {}; % To keep track of unique signal names
indicesToRemove = []; % Indices of duplicate signals to remove
for i = 1:logsout.numElements
% Get the name of the current signal
signalName = logsout.getElement(i).Name;
% Check if this name is already in the list of unique names
if any(strcmp(uniqueNames, signalName))
% If it is, mark this index for removal
indicesToRemove = [indicesToRemove, i];
else
% If it's not, add it to the list of unique names
uniqueNames{end+1} = signalName;
end
end
% Remove duplicates from logsout
logsout = logsout.removeElements(indicesToRemove);
This script works by maintaining a list of unique signal names encountered as it iterates through each element in logsout. If it encounters a signal whose name is already in the list, it marks that signal for removal. After identifying all duplicates, it removes them from logsout.
Please refer to the following documentation for more information about 'removeElements' function:
I hope this helps!

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!