Home > vbmeg > external > mne > mne_read_epoch.m

mne_read_epoch

PURPOSE ^

SYNOPSIS ^

function [data,fid] = mne_read_epoch(epoch_info,which,prev_fid)

DESCRIPTION ^

 [data,fid] = mne_read_epoch(epoch_info,which,prev_fid)

 Reads an epoch from a binary file produced by mne_epochs2mat

 epoch_info - The data structure read from the epoch data description file
 which      - Which epoch to read
 prev_fid   - Open file id from previous call
              if prev_fid < 0 or missing, the file will be opened
              The the current file id will be returned in the
              output argument fid, if present. If this argument is
              missing, file will be close upon exit from this function.

 The data will contain nchan x ntimes calibrated values

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data,fid] = mne_read_epoch(epoch_info,which,prev_fid)
0002 %
0003 % [data,fid] = mne_read_epoch(epoch_info,which,prev_fid)
0004 %
0005 % Reads an epoch from a binary file produced by mne_epochs2mat
0006 %
0007 % epoch_info - The data structure read from the epoch data description file
0008 % which      - Which epoch to read
0009 % prev_fid   - Open file id from previous call
0010 %              if prev_fid < 0 or missing, the file will be opened
0011 %              The the current file id will be returned in the
0012 %              output argument fid, if present. If this argument is
0013 %              missing, file will be close upon exit from this function.
0014 %
0015 % The data will contain nchan x ntimes calibrated values
0016 %
0017 
0018 %
0019 %
0020 %   Author : Matti Hamalainen, MGH Martinos Center
0021 %   License : BSD 3-clause
0022 %
0023 %
0024 %     $Id: mne_read_epoch.m 8776 2013-11-14 09:04:48Z roboos $
0025 %
0026 %     Revision 1.6  2006/05/03 19:03:19  msh
0027 %     Eliminated the use of cast function for Matlab 6.5 compatibility
0028 %
0029 %     Revision 1.5  2006/04/23 15:29:41  msh
0030 %     Added MGH to the copyright
0031 %
0032 %     Revision 1.4  2006/04/10 23:26:54  msh
0033 %     Added fiff reading routines
0034 %
0035 %     Revision 1.3  2006/02/21 03:35:35  msh
0036 %     Improved help text of mne_read_epoch.m
0037 %
0038 %     Revision 1.2  2006/02/21 03:26:02  msh
0039 %     Improved mne_read_epoch.m
0040 %
0041 %     Revision 1.1  2006/02/20 15:45:05  msh
0042 %     Added mne_find_channel.m and mne_read_epoch.m
0043 %
0044 %
0045 me='MNE:mne_read_epoch';
0046 if(nargin ~= 2 && nargin ~= 3)
0047    error(me,'Usage : [data,fid] = mne_read_epoch(epoch_info,which,prev_fid)');
0048 end
0049 
0050 if (which < 0) 
0051    error(me,'Epoch number must be positive');
0052 end
0053 
0054 if (which > epoch_info.nepoch)
0055     error(me,'Epoch number too large');
0056  end
0057 
0058 if (epoch_info.epochs(which,1) ~= 4)
0059    error(me,'Epoch is not in float format');
0060 end
0061 
0062 % open it as a big-endian file
0063 if (nargin < 3 || prev_fid < 0) 
0064    [fid,message] = fopen(epoch_info.epoch_file, 'rb', 'b') ;
0065    if (fid < 0)
0066       error(me,message);
0067    end
0068 else
0069    fid = prev_fid;
0070 end
0071 
0072 pos   = double(epoch_info.epochs(which,2));
0073 nsamp = double(epoch_info.epochs(which,5));
0074 nchan = double(epoch_info.nchan);
0075 
0076 if (fseek(fid,pos,'bof') < 0)
0077   error(me,'Could not position file to the epoch');
0078 end
0079 
0080 data = fread(fid, [nchan,nsamp], 'float','ieee-be');
0081 cal = diag(epoch_info.ch_cals(:,1))*diag(epoch_info.ch_cals(:,2));
0082 data = cal*data;
0083 
0084 if (nargout == 1)
0085    fclose(fid);
0086 end
0087 
0088 return;
0089 
0090 
0091 
0092 
0093 
0094

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005