Writing tables within a for loop
Hi all,
I’m trying to make a for loop to process some EEG data. The final output is (1×96) for each participant which is finally working great, however, now I’m having issues writing the data/ looping through the participants. I’ve attached what the output looks like for one particpant as that is how far I can get. Below is what I’m trying to use unnsuccessfully. Any help is greatly appreciated!
SubjectNum = { ’01-02′ ’01-03′ };
resultsFileName = [fullfile(baseDir, ‘MATLAB_Output’, ‘DIVINE.75results.xlsx’)];
for k = 1:length(SubjectNum)
…. (whole bunch of steps)
RelativePowerResults = table(ID,channelsLabel,relativeDelta2,relativeTheta2,relativeAlpha2,relativeBeta2,relativeGamma2)
% unstack resulting in (1 row with 96 columns)
RelativePowerResults_Wide = unstack(RelativePowerResults,"relative"+["Alpha2","Delta2","Theta2","Beta2","Gamma2"],’channelsLabel’);
if k == 1
% First subject, with variable names
writetable(RelativePowerResults_Wide, resultsFileName, ‘Sheet’, 1, ‘Range’, RANGE{k});
else
% For subsequent subjects, write without variable names
writetable(RelativePowerResults_Wide, resultsFileName, ‘Sheet’, 1, ‘Range’,RANGE{k}, ‘WriteVariableNames’, false);
endHi all,
I’m trying to make a for loop to process some EEG data. The final output is (1×96) for each participant which is finally working great, however, now I’m having issues writing the data/ looping through the participants. I’ve attached what the output looks like for one particpant as that is how far I can get. Below is what I’m trying to use unnsuccessfully. Any help is greatly appreciated!
SubjectNum = { ’01-02′ ’01-03′ };
resultsFileName = [fullfile(baseDir, ‘MATLAB_Output’, ‘DIVINE.75results.xlsx’)];
for k = 1:length(SubjectNum)
…. (whole bunch of steps)
RelativePowerResults = table(ID,channelsLabel,relativeDelta2,relativeTheta2,relativeAlpha2,relativeBeta2,relativeGamma2)
% unstack resulting in (1 row with 96 columns)
RelativePowerResults_Wide = unstack(RelativePowerResults,"relative"+["Alpha2","Delta2","Theta2","Beta2","Gamma2"],’channelsLabel’);
if k == 1
% First subject, with variable names
writetable(RelativePowerResults_Wide, resultsFileName, ‘Sheet’, 1, ‘Range’, RANGE{k});
else
% For subsequent subjects, write without variable names
writetable(RelativePowerResults_Wide, resultsFileName, ‘Sheet’, 1, ‘Range’,RANGE{k}, ‘WriteVariableNames’, false);
end Hi all,
I’m trying to make a for loop to process some EEG data. The final output is (1×96) for each participant which is finally working great, however, now I’m having issues writing the data/ looping through the participants. I’ve attached what the output looks like for one particpant as that is how far I can get. Below is what I’m trying to use unnsuccessfully. Any help is greatly appreciated!
SubjectNum = { ’01-02′ ’01-03′ };
resultsFileName = [fullfile(baseDir, ‘MATLAB_Output’, ‘DIVINE.75results.xlsx’)];
for k = 1:length(SubjectNum)
…. (whole bunch of steps)
RelativePowerResults = table(ID,channelsLabel,relativeDelta2,relativeTheta2,relativeAlpha2,relativeBeta2,relativeGamma2)
% unstack resulting in (1 row with 96 columns)
RelativePowerResults_Wide = unstack(RelativePowerResults,"relative"+["Alpha2","Delta2","Theta2","Beta2","Gamma2"],’channelsLabel’);
if k == 1
% First subject, with variable names
writetable(RelativePowerResults_Wide, resultsFileName, ‘Sheet’, 1, ‘Range’, RANGE{k});
else
% For subsequent subjects, write without variable names
writetable(RelativePowerResults_Wide, resultsFileName, ‘Sheet’, 1, ‘Range’,RANGE{k}, ‘WriteVariableNames’, false);
end for loop, eeg MATLAB Answers — New Questions