Back to the main page.
Bug 817 - Error when attemping read_sbin_events on a file without events
Status | CLOSED FIXED |
Reported | 2011-07-14 13:57:00 +0200 |
Modified | 2011-09-14 14:33:28 +0200 |
Product: | FieldTrip |
Component: | fileio |
Version: | unspecified |
Hardware: | PC |
Operating System: | All |
Importance: | P1 minor |
Assigned to: | Joseph Dien |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
German Gomez-Herrero - 2011-07-14 13:57:06 +0200
If I attempt to read events from an EGI sbin file that does not contain any events the following strage error is triggered: Error in ==> fileio\private\read_sbin_events at 37 fid=fopen([filename],'r'); ??? Output argument "EventCodes" (and maybe others) not assigned during call to "D:\mlib\fieldtrip\fileio\private\read_sbin_events.m>read_sbin_events". Error in ==> ft_read_event at 657 [EventCodes, segHdr, eventData] = read_sbin_events(filename); I say the error is strange because even though it seems to be caused by the absence of events in the file, setting up a breakpoints around the file I did not manage to locate the line that was actually causing the error (e.g. line 37 of read_sbin_events was running fine in debugging mode and MATLAB). However I managed to reproduce the error both in MATLAB R2010a on Windows and MATLAB R2010b on Linux. The error can be easily avoided by adding the following lines on line 115 of read_sbin_events: if NEvent == 0, EventCodes = []; segHdr = []; eventData = []; fclose(fid); return; end
Robert Oostenveld - 2011-07-14 14:09:12 +0200
could you try adding EventCodes = []; segHdr = []; eventData = []; at the beginning of read_sbin_events, i.e. prior to "fopen"? These respective variables are only defined in the if/for loops, which means that it might well be that in your case they remain undefined. If it works, I suggest that Joe approves of it and makes the final change+commit.
German Gomez-Herrero - 2011-07-14 14:36:37 +0200
(In reply to comment #1) > could you try adding > EventCodes = []; > segHdr = []; > eventData = []; > at the beginning of read_sbin_events, i.e. prior to "fopen"? > > These respective variables are only defined in the if/for loops, which means > that it might well be that in your case they remain undefined. > > If it works, I suggest that Joe approves of it and makes the final > change+commit. Thanks for the fast reaction! Yes adding those 3 lines at the beginning of the file also solves the problem. However, I would recommend returning from the function as soon as you know that there are no events in the file, i.e. keeping the if NEvent == 0, return; end around line 115. The earlier you leave the execution of the file the less chances for MATLAB to trigger an error ;) Best, Germán
Joseph Dien - 2011-08-19 05:22:21 +0200
Sorry for taking so long to get to this! The reason for the odd error at line 37 is that Matlab has a confusing behavior for dealing with the situation where a function exits with some of the output variables unassigned. In this case, it claims the error to be at the very first line of code (other than comments), which in this case was line 37. Anyway, initializing the variables as Robert suggested precludes this problem from happening. Thanks for the report!