Continue if file doesn't exist - pop_loadset

6 ビュー (過去 30 日間)
bruno mansur
bruno mansur 2020 年 3 月 16 日
コメント済み: bruno mansur 2020 年 3 月 16 日
I want my pop_events function to be executed to all '.set' files in a directory. The files are named as p[1:44]_0[1:3].set.
My code is the following:
sub = [1:44];
run = [1:3];
for i = sub
for j = run
EEG = pop_loadset('filename',sprintf('p0%i_%i.set', i,j),'filepath','.../2_correctTriggers/');
EEG = eeg_checkset( EEG );
pop_expevents(EEG, sprintf('.../p0%i_%i.csv', i, j), 'seconds');
end
end
But there are some missing files, like the p02_03.set, so the for loop returns this message when it comes to this file:
Error using load
Unable to read file
'.../2_correctTriggers/p02_3.set'.
No such file or directory.
Error in pop_loadset (line 119)
TMPVAR = load('-mat', filename);
Error in extract_log_files (line 6)
EEG = pop_loadset('filename',sprintf('p0%i_%i.set',
i,j),'filepath','.../2_correctTriggers/');
How can I write a code that skips inexistent files and continue the loop?
I would really appreciate any help,
Cheers

採用された回答

Jakob B. Nielsen
Jakob B. Nielsen 2020 年 3 月 16 日
Use the exist or isfile functions.
E.g.
for i = sub
for j = run
if exist(['.../2_correctTriggers/',sprintf('p0%i_%i.set', i,j)])
EEG = pop_loadset('filename',sprintf('p0%i_%i.set', i,j),'filepath','.../2_correctTriggers/');
EEG = eeg_checkset( EEG );
pop_expevents(EEG, sprintf('.../p0%i_%i.csv', i, j), 'seconds');
else
%do nothing
end
end
end
  1 件のコメント
bruno mansur
bruno mansur 2020 年 3 月 16 日
It works wonderfully! Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEEG/MEG/ECoG についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by