neauscan自帶軟件scan導出的.avg格式文件如何在matlab裏面畫圖

新手在處理腦電的時候不可避免的會使用scan這樣的商業軟件,然後處理完數據以後可能會想導入到matlab進行畫圖,可是商量軟件導出的文件格式可能並不那麼自由,這裏提供一個將scan處理完的腦電數據導出到matlab並畫圖的腳本如下


%
% Written By Yizhou
% Using the code without proper understanding the code and relevant background
% of EEG may lead to confusion, incorrect data analyses,or misinterpretations
% of results.
% The author assumes NO responsibility for inappropriate or incorrect use
% of this code.
% WX:         17373158786


% 使用neauscan提供的scan軟件分析的腦電數據疊加平均以後會得到一個avg格式的文件,如果想要導出到matlab裏面畫圖貌似並沒有現成的方法
% 而eeglab界面並沒有提供一個現成的選擇框載入.avg文件,但是可以使用函數eeg_load_scan4_avg獲得,這是本腳本的核心代碼如下;

% 函數:eeg_load_scan4_avg
% 
% 用法:[f,fid] = eeg_load_scan4_avg(filename)
% 
% 
% 
% 變量介紹:
% 
% f:這是一個結構體,裏面包含了avg數據的所有內容,類似於讀cnt的那個函數的輸出變量,這個結構體裏面包含
% 
% f.header        - general header parameters
% 
% f.electloc      - channel specific parameters
% 
% f.data.header   - small channel data header
% 
% f.data.samples  - channel data (not uV)
% 
% f.variance      - channel variance
% 
% f.tag           - scan4.1 file tags
% 
% fid: 文件的一個指針,這裏基本沒啥用
% 
% filename:文件名,和loadcnt當中的file一樣。




%% 祭天
clear all;clc;
load('EEG.mat');

%% 載入數據 ERP的繪製
fig_path = 'D:\Docu\Project\draw_pic\data\ERP';cd(fig_path);
% 讀取所有的avg格式文件;
fig_files = dir([fig_path,filesep,'*.avg']);
% 對每個文件進行讀取
for fig_No = 1:length(fig_files)
    exp_con_name = fig_files(fig_No).name(1:end-4)
    % 每個avg文件生成一個文件夾
    mkdir([fig_path,filesep,exp_con_name]);cd([fig_path,filesep,exp_con_name]);
    % 讀取avg文件
    [f,fid] = eeg_load_scan4_avg(['D:\Docu\Project\draw_pic\data',filesep,fig_files(fig_No).name]);
    % 將avg文件內的數據轉爲數組形式
    for i = 1:65
        EEG_avg(i,:)=(f.data(i).samples)';
    end
    % 每個通道電極點
    for chan_point = 1:65
        % chan_point = 28;
        % 因爲不可知的原因,數據需要除以20才能得到真實的幅值
        mean_data = squeeze(EEG_avg(chan_point,:))./20; 
        figure;
        plot(EEG.times, mean_data,'linewidth', 1.5); %% plot waveforms for different conditions
        set(gca,'YDir','reverse','XAxisLocation','origin','YAxisLocation','origin','LineWidth',2.0,'box','off');
        axis([-200 1000 -4 12]);  %% define the region to display
        title(['Group level data at',EEG.chanlocs(chan_point).labels],'fontsize',16);
        xlabel('Latency (ms)','fontsize',16);
        ylabel('Amplitude (uV)','fontsize',16);
        print(gcf,[exp_con_name,'_',EEG.chanlocs(chan_point).labels],'-dpdf','-r600');
        print 1.eps -depsc2 -r600;
        % 由於不知道如何設定合適的文件名,所以保存以後再使用下面的函數進行修改文件名
        movefile('1.eps',[exp_con_name,'_',EEG.chanlocs(chan_point).labels,'.eps']);
        close all;
    end
end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章