필터 지우기
필터 지우기

How to delete dublicate entries in logsout

조회 수: 5 (최근 30일)
Max Wagenblast
Max Wagenblast 2021년 9월 16일
답변: Pratik 2024년 4월 16일
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?

답변 (1개)

Pratik
Pratik 2024년 4월 16일
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!

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by