From 6dee81b473dc5e864db9b2f4195ef048012ce868 Mon Sep 17 00:00:00 2001 From: Dominik Bach Date: Thu, 27 Jun 2024 09:18:26 +0100 Subject: [PATCH] fix edge case of empty epochs file in pspm_trim --- src/pspm_trim.m | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pspm_trim.m b/src/pspm_trim.m index ed0b7e2c3..89dde9cd8 100644 --- a/src/pspm_trim.m +++ b/src/pspm_trim.m @@ -320,17 +320,21 @@ if ~isempty(options.missing) [lsts, epochs] = pspm_get_timing('epochs', options.missing, 'seconds'); if lsts < 1, return; end - index = epochs(:, 2) < sta_time | ... - epochs(:, 1) > sto_time | ... - epochs(:, 1) > infos.duration; - epochs(index, :) = []; - epochs = epochs - sta_time; if ~isempty(epochs) - epochs(1, 1) = max([0, epochs(1, 1)]); - epochs(end, 2) = min([infos.duration, epochs(end, 2)]); + index = epochs(:, 2) < sta_time | ... + epochs(:, 1) > sto_time | ... + epochs(:, 1) > infos.duration; + epochs(index, :) = []; + epochs = epochs - sta_time; + if ~isempty(epochs) + epochs(1, 1) = max([0, epochs(1, 1)]); + epochs(end, 2) = min([infos.duration, epochs(end, 2)]); + end + lsts = pspm_get_timing('epochs', epochs, 'seconds'); + if lsts < 1, return; end + else + % do nothing and keep the empty epochs array end - lsts = pspm_get_timing('epochs', epochs, 'seconds'); - if lsts < 1, return; end [pth, fn, ext] = fileparts(options.missing); newepochfile = fullfile(pth, ['t', fn, ext]); save(newepochfile, 'epochs');