Saving an array of complex numbers within a loop
显示 更早的评论
Hi,
I have written the following script that computes an FFT on some EEG data and plots and saves various conditions for each subject
My question is how to save the FFT data for each subject then average them all together and produce a 'Grand Average' FFT plot of all subjects?
Many thanks for your help
%Subject info, folder needs to be same name
subject = {'02', '03', '04','05','06','07','08','09'};
condition = {'pre_low_lum_CleanICA', '40_low_lum_CleanICA', 'post_low_lum_CleanICA','pre_high_lum_CleanICA', '40_high_lum_CleanICA', 'post_high_lum_CleanICA'};
%Axis windows
axtimes = [1 45 0 1.2];
figure;
for i = 1:length(subject);
for j = 1:length(condition);
%% use sprintf to create file path for each file
% subjectpath = sprintf('%s\\%s\\%s.set', pathAll, subject{i}, condition{j});
% subjectpath_save = strrep(subjectpath, '.cnt', '.set');
%Load the file from prepocessed .SET file
fname = sprintf('%s_%s.set',subject{i}, condition{j});
datapath = sprintf('%s%s',homedir, subject{i})
fprintf('\n\n\n**** %s : Loading ****\n\n\n', fname);
EEG = pop_loadset('filename',fname,'filepath',datapath);
%% ----------------------------- FFT Parameters -----------------------------
L = 307200;
%x= EEG.pnts-307200
%specifry channel here 31 = Oz CHECK CHANNEL NUMBER IS CORRECT
y = EEG.data(31, :);
Fs = EEG.srate;
%FFT
% Reshape subplot
index = reshape(1:6, 2, 3).';
subplot(3, 2, index(j));
NFFT = L;
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)));
axis([axtimes]) ;
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
cond = condition{j}(1:end-9);
title(sprintf('FFT: Subject %s, Condition = %s', subject{i}, cond),'interpreter', 'none');
hold on
fprintf('\n\n\n**** %s: FINISHED ****\n\n\n', fname);
end
%Save current figure
fname = sprintf('%sFFT_%s.png',savepath, subject{i});
saveas(gcf,fname);
% Close current figure and run for next subject
close all
end
fprintf('\n\n\n**** Script FINISHED ****\n\n\n');
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!