Path: news.mathworks.com!not-for-mail
From: "Ben " <ben.cowley@helsinki.fi>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Compiled Matlab fgets error
Date: Thu, 4 Oct 2012 15:48:09 +0000 (UTC)
Organization: Helsingin Yliopiston Observatorio
Lines: 48
Message-ID: <k4kb3p$rcq$1@newscl01ah.mathworks.com>
References: <k2o940$q1o$1@newscl01ah.mathworks.com> <k2oa8k$g25$1@speranza.aioe.org> <k2p4l7$qf6$1@newscl01ah.mathworks.com> <k2p97h$bh5$1@newscl01ah.mathworks.com> <k2q1f6$60t$1@speranza.aioe.org> <k2q7b9$rtg$1@newscl01ah.mathworks.com> <k2q83s$omi$1@speranza.aioe.org>
Reply-To: "Ben " <ben.cowley@helsinki.fi>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1349365689 28058 172.30.248.47 (4 Oct 2012 15:48:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Oct 2012 15:48:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3269771
Xref: news.mathworks.com comp.soft-sys.matlab:779876

Well the solution to that particular problem was to use the mex version of the EEG read function which were available from the Biosig website. 

meta = mexSOPEN( fin );
data = mexSLOAD( fin );

where 'fin' is the filename.
The use of the mex functions completely solved the issue of invalid Fid, however to actually use the EEG data which was read, several functions from the Eeglab toolbox are still used - this means they expect the same data format that would be returned by using the pop_biosig() function from Eeglab. The mex functions DO NOT return exactly the same format, thus an explicit conversion is needed, which is given below.
Hope this helps someone, sometime!

<code>
function eeg = mexican( fin )
%%
% PURPOSE:  Return the pop_biosig-style data structure of EEG read by mex functions.
% PARAMS:   'fin' - the input file, a gdf
% USAGE:    
% Note:     
% CALLS:    mexSOPEN(), mexSLOAD()

    % Load the file meta-data
    meta = mexSOPEN( fin );
    data = mexSLOAD( fin );
    % Transposed data
    eeg.data = data';
    % Start converting names and matrix orientation etc
    eeg.nbchan = meta.NS;
    eeg.trials = meta.SPR;
    eeg.pnts = meta.NRec;
    eeg.srate = meta.SampleRate;
    for i = 1:meta.NS
        eeg.chanlocs(i).labels = meta.Label(i);
        eeg.chanlocs(i).ref = '';
    end
    eeg.ref = 'common';
    eeg.comment = ['Original file: ' meta.FileName];
    eeg.event = meta.EVENT;
    % These fields have no equivalent from the mex load
    [eeg.filepath, eeg.filename, ~] = fileparts( fin );
    eeg.subject = '';
    eeg.group = '';
    eeg.condition = '';
    eeg.session = [];
    eeg.xmin = [];
    eeg.xmax = [];
    eeg.times = [];
    eeg.epoch = [];
    eeg.etc = [];

</code>