Continue if file doesn't exist - pop_loadset
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!