Hi Carmen,
I understand that you want to automate the process of calculating phase-correlation (PLV) values for every participant for every frequency and store them in a matrix. Here's how you can modify your script to achieve this:
% Names of the channels you want to compute connectivity between
channel1 = 'F7';
channel2 = 'FC1';
% Frequencies to iterate over
frequencies = 1:30;
nfreq = length(frequencies);
% Preallocate phase synchronization matrix
phase_synchronization_all = zeros(nfreq, length(filenames_TDCS_I));
% Iterate over frequencies
for freq_idx = 1:nfreq
center_freq = frequencies(freq_idx);
% Generate wavelet for current frequency
wavelet = exp(2*1i*pi*center_freq.*time) .* exp(-time.^2./(2*(4/(2*pi*center_freq))^2));
% Iterate over participants
for filenr = 1:length(filenames_TDCS_I)
file_name_current = char(filenames_TDCS_I(filenr));
EEGdataset = pop_loadset('filename', file_name_current, 'filepath', filepath2);
% Calculate PLV for current participant and frequency
% (Replace the following line with your PLV calculation code)
phase_synchronization_all(freq_idx, filenr) = calculate_PLV(EEGdataset, channel1, channel2, wavelet);
end
end
In this modified script:
- You iterate over frequencies from 1 to 30 using frequencies = 1:30.
- For each frequency, you generate the wavelet.
- Then, you iterate over participants and calculate PLV for each frequency and each participant, storing the results in the phase_synchronization_all matrix.
Make sure to replace calculate_PLV with your actual PLV calculation code.
Let me know if you need further assistance!
Hope this helps.
Regards,
Nipun