forked from arnodelorme/mffmatlabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmff_export.m
64 lines (58 loc) · 2.13 KB
/
mff_export.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
% mff_export - export EEGLAB structure to MFF file. This function calls
% all other function to create MFF structure, export
% events, channels and channel coordinates.
%
% Usage:
% mff_export(EEG, mffFile);
%
% Inputs:
% EEG - EEGLAB structure
% mffFile - filename/foldername for the MFF file (MFF file/folder must
% already exist)
% This file is part of mffmatlabio.
%
% mffmatlabio is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% mffmatlabio is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with mffmatlabio. If not, see <https://www.gnu.org/licenses/>.
function mff_export(EEG, outputFile)
matVer = ver('MATLAB');
if exist('OCTAVE_VERSION', 'builtin') == 0 && datenum(matVer.Date) < 735595
error('This version of Matlab is too old. Use version 2014a or later');
end
% add mff extension if not present
[filePath, fileName] = fileparts( outputFile);
outputFile = fullfile(filePath, [ fileName '.mff' ]);
% delete folder if it exist
if exist(outputFile)
rmdir(outputFile, 's');
end
mff_createmff(outputFile);
if ~isfield(EEG.etc, 'recordingtime')
EEG.etc.recordingtime = now;
EEG.etc.timezone = '00:00';
end
mff_exportinfo(EEG, outputFile);
mff_exportsubject(EEG, outputFile);
mff_exportinfon(EEG, outputFile,1);
if isfield(EEG.etc, 'info2')
mff_exportinfon(EEG, outputFile, 2);
end
mff_exportsignal(EEG, outputFile);
indtle = mff_exportcategories(EEG, outputFile);
EEG.event(indtle) = []; % remove time locking events
mff_exportevents(EEG, outputFile);
mff_exportcoordinates(EEG, outputFile);
mff_exportsensorlayout(EEG, outputFile);
mff_exportpnsset(EEG, outputFile);
mff_exportepochs(EEG, outputFile);
mff_exportsensorlayout(EEG, outputFile);
disp('Done');