ET_PDToolkit/PDToolkit/@PDTrial/removeDuplicateLabels.m

43 lines
1.0 KiB
Matlab

function[obj n] = removeDuplicateLabels(obj)
%% Remove duplicate labels which may have been created in the trial object
if isempty(obj.labels)
return
end
times = [obj.labels.time];
labels = {obj.labels.label};
labels_to_prune = [];
for l = 1:length(times)
current_label_time = times(l);
current_label = labels{l};
other_ind = setdiff(1:length(times),l);
%% match timings
identical_timings_ind = find(times(other_ind)==current_label_time);
if isempty(identical_timings_ind)
continue;
else
for i = 1:length(identical_timings_ind)
% match label
if (strcmp(labels{identical_timings_ind(i)}, current_label))
labels_to_prune = [labels_to_prune identical_timings_ind(i)];
end
end
end
end
n = length(labels_to_prune);
label_struct = obj.labels;
label_stuct(labels_to_prune) = []; % remove duplicates
obj.labels = label_struct; % store pruned set of labels