Reshape EEG data to wide format with new aggregate column names
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm using EEG lab to calculate relative spectral power for various bands. This went well, but now I'm stuck on how to reshape this the way I need it. I have 20 participants, and I want each participant to have only one row of data.
As such, I'm trying to convert this matrix so that the columns are a combination of electrode and frequency band. For example, each participant would have one row of data with columns labelled F7.relativeAlpha, F7.relativeBeta, and so on (see below for example). Any help would be greatly appreciated! I added an example of what I'm trying to create vs what I have currently.
I've tried unsuccessfully with the reshape function and with the unstack function.
RelativePowerWide = unstack(RelativePowerResults,'ID','RelativeDelta')
댓글 수: 0
채택된 답변
Voss
2025년 1월 28일
% a table
ID = ["01-02";"01-02";"01-02";"01-02";"01-02";"01-02";"01-02";"01-12";"01-12";"01-12";"01-12";"01-12";"01-12"];
Electrode = {'F7';'FP1';'FP2';'F8';'F3';'Fz';'F4';'F7';'FP2';'F8';'F3';'Fz';'F4'};
N = numel(ID);
RelativeDelta = rand(N,1);
RelativeTheta = rand(N,1);
RelativeBeta = rand(N,1);
RelativeGamma = rand(N,1);
T = table(ID,Electrode,RelativeDelta,RelativeTheta,RelativeBeta,RelativeGamma)
% unstack
Tnew = unstack(T,"Relative"+["Delta","Theta","Beta","Gamma"],'Electrode');
% adjust new variable names if needed
vars = Tnew.Properties.VariableNames(2:end);
vars = regexprep(vars,'(.*)_(.*)','$2.$1');
Tnew.Properties.VariableNames(2:end) = vars;
Tnew
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!