Clear Filters
Clear Filters

EEGLAB - Edit event type with for loop

15 views (last 30 days)
COLLART Aymeric on 19 Aug 2018
Commented: Thomas Feiner on 10 Dec 2018
I will try to be the most precise and clear possible.
I am currently analyzing EEG data, using Matlab and EEGLAB. Here is a brief description of the experiment design: I showed sentences (word-by-word, five words for one sentence) to participants, with four conditions. For each word that appeared on the screen, a code was sent to the data acquisition system, so that I can epoch them afterwards. I give an example here of the codes that have been sent, for the four conditions:
  • Condition 1 - 1 21 31 41 51
  • Condition 2 - 1 22 32 42 52
  • Condition 3 - 1 22 33 43 53
  • Condition 4 - 1 21 34 44 54
I won't analyze the first word. But I realized that for the second word, I can't analyze according to the four conditions, since I haven't specified enough... (I'll know for the next time!)
What I would like to obtain is:
  • Condition 1 - 1 21 31 41 51
  • Condition 2 - 1 22 32 42 52
  • Condition 3 - 1 23 33 43 53
  • Condition 4 - 1 24 34 44 54
Simply said: "If the coding is 22 and the one after is 33, then change 22 to 23" and "If the coding is 21 and the one after is 34, then change 21 to 24".
With EEGLAB, I could do it manually, by going into the Workspace variable "ALLEEG", then going to "ALLEEG.event", where I obtain this:
But If I had to do it manually, it's like 700 event codes to check, for more than 30 participants...
I have the impression that this could be done easilly with for loop and if condition. But here I'm blocked with two problems. The first one is that I am not familiar with Matlab (but with R, so it must be similar I guess), the second one is that I don't see how to write the loop!
Do you have any idea on how I could do it? Thanks in advance!
  1 Comment
Thomas Feiner
Thomas Feiner on 10 Dec 2018
I have a question. I understand that there you can see the latency of the event show in sample rate. How can I see that in milisecond or how much miliseconds does a sample has?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 19 Aug 2018
Use strrep
s = strrep(s, '22 33', '23 33');
and so on. If there are more than those two cases you mentioned, and tehre is some pattern, then create strings with sprintf():
for k = 1 : whatever
% Construct bad string you want to replace.
s1 = sprintf(......
s2 = sprintf(......
sBad = sprintf('%s %s', s1, s2);
% Construct good string you want to replace it with.
s1 = sprintf(......
s2 = sprintf(......
sGood = sprintf('%s %s', s1, s2);
% Do the replacement
s = strrep(s, sBad, sGood);
A little known trick: strrep() works (at least for now, despite a warning) with numbers:
s = [1,2,3,4,5]
s = strrep(s, [3,4], [333,444])
  1 Comment
Image Analyst
Image Analyst on 19 Aug 2018
Please attach your ALLEEGevent table in a .mat file if you still need help.

Sign in to comment.


Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!