How do I run ICA only on certain channels using the code for pop_runica in Matlab eeglab?

31 views (last 30 days)
Hi all,
I have an EEG.data matrix including 21 EEG channels (1:21, :), and 1 ECG channel (22, :).
I am trying to write a code to run pop_runica in eeglab, so I can run it from the Editor Window instead of using the GUI.
When using the GUI, I select Tools > Decompose data by ICA > runica and I select EEG as my channel types. This allow me to run ICA on EEG channels only (excluding my ECG channel).
However, this selection does not appear in the code when I call eegh, and I am unable to make this data selection when I use a code in the editor window. The 'chanid' specification from the pop_runica() function should allow to specify what channels I want to run the ICA on, but if I specify it, I get the following error: " Output argument "sphere" (and maybe others) not assigned during call to "runica". Error in pop_runica (line 439) [EEG.icaweights,EEG.icasphere] = runica( tmpdata, 'lrate', 0.001, g.options{:} ); Error in SSS_preprocess (line 99) EEG = pop_runica(EEG, 'icatype', 'runica', 'extended',1, 'interrupt', 'on', 'chanid', EEG.data((1:21), :), 'pca', EEG.eegrank);
I am using the following code:
%% 2. Run ICA
[EEG ALLEEG CURRENTSET] = eeg_retrieve(ALLEEG,1);
EEG = eeg_checkset( EEG );
EEG.eegrank = EEG.nbchan - size(EEG.etc.noiseDetection.interpolatedChannelNumbers, 2) - 2; % Nbchan minus interpolated channels, reference channel, and ECG.
EEG = pop_runica(EEG, 'icatype', 'runica', 'extended',1, 'interrupt', 'on', 'chanid', EEG.data(1:21, :), 'pca', EEG.eegrank);
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
Please would you be able to help? What should I specify after 'chanid' to select only my EEG data for ICA?
Many thanks in advance!!
Irene

Answers (1)

Vatsal
Vatsal on 31 Jan 2024
Hi Irene,
The ‘chanid’ parameter in the “pop_runica” function is used to specify the channels on which you want to run the ICA. The ‘chanid’ parameter should be a vector of channel indices, not the actual EEG data. So, if you want to run ICA on the first 21 channels, you should pass a vector from 1 to 21 to ‘chanid’.
Here is how you can modify your code:
%% 2. Run ICA
[EEG, ALLEEG, CURRENTSET] = eeg_retrieve(ALLEEG, 1);
EEG = eeg_checkset(EEG);
EEG.eegrank = EEG.nbchan - size(EEG.etc.noiseDetection.interpolatedChannelNumbers, 2) - 2;
% Specify the channel indices for EEG channels only (1 to 21)
chanidx = 1:21;
% Run ICA on the specified EEG channels
EEG = pop_runica(EEG, 'icatype', 'runica', 'extended', 1, 'interrupt', 'on', 'chanind', chanidx, 'pca', EEG.eegrank);
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
Please note that I have corrected 'chanid' to 'chanind', which is the appropriate argument for specifying channel indices in the “pop_runica” function.
To learn more about “pop_runica” usage and syntax, you may refer to the link below: -
I hope this helps!

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!