0

我在 eeglab 中得到了一批处理过的数据集。我想将它们全部导出到 txt 中,但是,似乎必须逐个文件完成。

我是 eeglab 和 matlab 的新手。有人可以帮我吗?

4

1 回答 1

0

这段代码通过在我的目录中运行并带有 EEGLAB 进行了测试。就我而言,该目录中还有 2 个数据集与关联的 .fdt 文件。如果您的 .set 文件与 EEGLAB 位于不同的目录中,则必须更改代码才能在其中找到它们。该脚本必须在 EEGLAB 目录中,否则 EEGLAB 源代码必须在您的 PATH 中,但我认为不建议将 EEGLAB 的代码放在您的 PATH 中。

我使用正则表达式 ( regexp) 来查找哪些文件是 .set 文件并构建输出文件名。如果您不熟悉正则表达式,只需进行网络搜索即可。

% read all the files in the directory
files = dir();

% parse directory contents for .set files
sets = {};
idx = 1;
for n=1:length(files)
    if(regexp(files(n).name,'.set'))
        sets{idx} = files(n).name;
        idx = idx+1;
    end
end

% load the data sets and write the data to appropriate filename
for n=1:length(sets)
   % change the argument after filepath to the path your EEGLAB
   % instalation is in
   % note the double '\' directory delimiter is for Windows
   EEG = pop_loadset('filename', sets{n},'filepath','C:\\Users\\david.medine\\matlab\\toolboxes\\eeglab2019_0\\');
   EEG = eeg_checkset( EEG ); 
   outputfilename = sprintf('%stxt', sets{n}(1:regexp(sets{n}, '.set')))
   writematrix(EEG.data, outputfilename);
end

顺便说一句,我知道从 EEGLAB 调用哪些函数来加载 .set 文件,方法是检查>> EEG.history. 这将显示 EEGLAB 会话中 GUI 幕后运行的所有 Matlab 代码。

EEGLAB 以矢量化方向存储数据。如果要多路复用,只需转置矩阵:

writematrix(EEG.data', outputfilename);
于 2022-03-03T03:41:39.847 回答