index channel location error

chan1idx = find(strcmpi(channel1,{EEG.chanlocs.labels}));
chan2idx = find(strcmpi(channel2,{EEG.chanlocs.labels}));
Dear all, I am trying to direct the index of channel 1 to the corresponding value in my EEG.chanlocs file.
But I keep on getting this error:
Intermediate dot '.' indexing produced a comma-separated list with 20 values, but
it must produce a single value to perform subsequent indexing operations.
What should I change?
Thanks!!

6 Comments

Your EEG is a non-scalar struct. You can only index one level into it.
It is not clear that EEG(K).chanlocs is a scalar struct itself, or that EEG(K).chanlocs(1).labels is scalar, and those things will matter for producing useful code.
Hey walter thank you for your answer.
If I go to my EEG.chanlocs file it looks like the screenshot, so know i directed it to EEG.chanlocs in parenthesis, because that is what matlab tells me to do, but then i get a variable chanidx but it is an empty matrix..
Your EEG is nonscalar struct. Each entry of it contains the nonscalar struct chanlocs. Each chanlocs contains labels which is a character vector.
When you do the find() are you asking to identify the EEG index for which some chanlocs.labels matches? Or are you asking to identify the chanlocs index that matches for some EEG? If you are trying to identify the J, K pair for which EEG(J).chanlocs(K).labels matches then you cannot do that with a single find()
Yes the last option "Or are you asking to identify the chanlocs index that matches for some EEG? If you are trying to identify the J, K pair for which EEG(J).chanlocs(K).labels matches then you cannot do that with a single find()"
So I want to calculate the phase-correlation between for example Fz and Fp, that have been earlier in my script classsified as channel1 and channel2. With this find I want to find the channel indices that match with my Fz and Fp.
Are the labels the same for all EEG entries?
Yes, so they are all labeled, and I am trying to match the channels that I choose to calculate the phase-correlation between with the matching labels in my EEG.chanloc file.

Sign in to comment.

 Accepted Answer

channel1 = 'Fz';
EEG(1).chanlocs = struct('labels', {'Fp1', 'Fz', 'F3'}, 'sph_theta', {18, 0, 39})
EEG = struct with fields:
chanlocs: [1×3 struct]
EEG(2).chanlocs = struct('labels', {'Fp1', 'Fz', 'F3'}, 'sph_theta', {68, 44, 90});
EEG(3).chanlocs = struct('labels', {'Fp1', 'Fz', 'F3'}, 'sph_theta', {-17, 23, 45});
fields = {EEG(1).chanlocs.labels}
fields = 1×3 cell array
{'Fp1'} {'Fz'} {'F3'}
[found_channel1, idx] = ismember(channel1, fields)
found_channel1 = logical
1
idx = 2
So now if found_channel1 is true then idx is valid and is the field number of channel1 in EEG(:).chanlocs .
This assumes that the channel labels are exactly the same for all EEG(K).chanlocs .
extracted_info = cell2mat(arrayfun(@(S) S.chanlocs(idx), EEG, 'uniform', 0))
extracted_info = 1×3 struct array with fields:
labels sph_theta
{extracted_info.labels}
ans = 1×3 cell array
{'Fz'} {'Fz'} {'Fz'}
[extracted_info.sph_theta]
ans = 1×3
0 44 23

1 Comment

Thank you so so much!! I have replicated all your steps and also for channel 2 and it works.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!