[Eeglablist] Apologies, MATLAB is not my first language... (spectopo() code error)
Ian Jackson
ianjackso at reed.edu
Wed Nov 18 03:50:53 PST 2020
Hi EEGLAB folks,
I've repurposed code from Makoto's useful code from the documentation (
https://sccn.ucsd.edu/wiki/Makoto's_useful_EEGLAB_code#How_to_extract_EEG_power_of_frequency_bands_.2806.2F06.2F2020_updated.29
)
*The purpose* is to generate mean power for 5 frequency bands over 61
components of ICA data. Each mean power generated for a trial/epoch is
normalized by dividing by the mean power of the corresponding baseline.
*The issue* is that, when running the following code, I get an error *"Unable
to perform assignment because the indices on the left side are not
compatible with the size of the right side." *The error occurs at the point
in the loop where j=3, i = 1 and channelIdx = 1, though the code works
completely fine without the baseline section.
************************************
*The code*
%% do PSD for each trial and normalize by baseline
freq_ranges = {[1 4],[5 8],[9 12],[13 30],[31 64]};
psd_data_norm = zeros([50 61 5]);
for j = 1:50 % each trial
current_data = squeeze(saved_shape_data(j,:,:));
current_baseline_data = squeeze(saved_baseline_data(j,:,:));
meanPowerMicroV = zeros([61 5]);
meanPowerMicroV_baseline = zeros([61 5]);
for i = 1:5 % for all frequency bands
for channelIdx = 1:61
% For shape
disp(channelIdx)
[psdOutDb(channelIdx,:), freq] =
spectopo(current_data(channelIdx, :), 0, 128, 'plot', 'off');
lowerFreqIdx = find(freq==freq_ranges{i}(1));
higherFreqIdx = find(freq==freq_ranges{i}(2));
meanPowerMicroV(channelIdx,i) = mean(10.^((psdOutDb(channelIdx,
lowerFreqIdx:higherFreqIdx))/10), 2);
% For corresponding baseline (this is the aforementioned
baseline section)
[psdOutDb_baseline(channelIdx,:), freq_baseline] =
spectopo(current_baseline_data(channelIdx, :), 0, 128, 'plot', 'off');
lowerFreqIdx = find(freq_baseline==freq_ranges{i}(1));
higherFreqIdx = find(freq_baseline==freq_ranges{i}(2));
meanPowerMicroV_baseline(channelIdx,i) =
mean(10.^((psdOutDb_baseline(channelIdx, lowerFreqIdx:higherFreqIdx))/10),
2);
end
meanPowerMicroV_norm = meanPowerMicroV ./ meanPowerMicroV_baseline; %
normalize
psd_data_norm(j,:,:) = squeeze(meanPowerMicroV_norm);
end
end
************************************
Here is some more useful information about the variables at the point of
error in the loop:
size(saved_shape_data) = [50 61 576]
size(saved_baseline_data) = [50 61 192]
size(spectopo(current_data(channelIdx, :), 0, 128, 'plot', 'off')) = [1 65]
size(freq) = [65 1] (it is an array [0,1,...,64])
size(spectopo(current_baseline_data(channelIdx, :), 0, 128, 'plot', 'off'))
= [1 65]
size(freq_baseline) = [128 1] (it is an array [0,1,..,127])
************************************
I suspect it has to do with freq_baseline due to its strangely large size,
but I am at a loss as to how to fix the error. Any help would be greatly
appreciated!
The general upkeep with correspondence on this forum is great to see. Thank
you and I look forward to hearing from you!
Regards,
Ian Jackson
Reed College
More information about the eeglablist
mailing list