subsetting from a structure array inside a for loop

3 visualizaciones (últimos 30 días)
Roberto Petrosino
Roberto Petrosino el 23 de Feb. de 2018
Respondida: Walter Roberson el 23 de Feb. de 2018
Hello everybody, I am trying to write up a code that opens a bunch of eeglab datasets (set format), and stores a part of it for later. Here's my attempt:
conditionList={
'subj1',
'subj2',
'subj3',
'subj4'
}
chan = 'Cz' % the channel to use
for i = 1:length(conditionList)
condition = char(conditionList(i));
EEG = pop_loadset('filename', [condition '.set'], 'filepath', '~/MATLAB/');
data = squeeze(EEG(i).data( strcmpi(chan, {EEG.chanlocs.labels}), :, 1:120));
% the subset of the data we want to look at
% EEG.data structure is made of three vectors: channels, points, and trials.
end
The following error pops up: "Index exceeds matrix dimensions". I am not an expert at matlab, so any advice would be greatly appreciated!

Respuestas (1)

Walter Roberson
Walter Roberson el 23 de Feb. de 2018
You have a comment that
% EEG.data structure is made of three vectors: channels, points, and trials
which suggests that any one EEG(i).data is a scalar structure with three fields . But in the line
data = squeeze(EEG(i).data( strcmpi(chan, {EEG.chanlocs.labels}), :, 1:120));
you are treating any one EEG(i).data as if it is a 3D array. Is it really true that you have a 3D array of structures, each with three fields? Or should you perhaps be going down one layer, such as
data = squeeze(EEG(i).data.points( strcmpi(chan, {EEG.chanlocs.labels}), :, 1:120));
??
I am also concerned because you have EEG(i), indicating that EEG is a structure array, and you have {EEG.chanlocs.labels} . With EEG being a structure array, for {EEG.chanlocs.labels} to be valid, each chanlocs would have to be a scalar structure, and each labels would have to be a character vector, which would tend to suggest that each EEG(i) is only for one channel, which would argue against the possibility that EEG(i).data being a structure array with channels as a field.

Categorías

Más información sobre EEG/MEG/ECoG en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by