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!