필터 지우기
필터 지우기

subsetting from a structure array inside a for loop

조회 수: 4 (최근 30일)
Roberto Petrosino
Roberto Petrosino 2018년 2월 23일
답변: Walter Roberson 2018년 2월 23일
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!

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 23일
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.

카테고리

Help CenterFile Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by