Home > Enterprise >  How to use a variable in Matlab's eeglab function
How to use a variable in Matlab's eeglab function

Time:12-24

I am attempting to use the following function in Matlab's eeglab toolkit to rename events, which meet certain criteria (i.e., their latency is between two numbers):

EEGfastrts = pop_selectevent( EEG, 'latency',’0 <= fastval’,'type',{'AnyResponse'},'renametype','FastRTs','deleteevents','off','deleteepochs','off','invertepochs','off');

However, when I input a variable (i.e., fastval), instead of an int value, this function does not work.

I was wondering if anyone might have suggestions/work-arounds for using this function for a value that is represented by a variable. My goal is to insert the function into a loop, which will alter the variable value with every iteration.

Thank you in advance for your thoughts and input.

CodePudding user response:

From the docs it expects that the 'latency' input is a char, so you need to create that using your variable. One option is to use sprintf() e.g:

fastval = 100; % some value
strLatency = sprintf( '0 < %.2f', fastval ); % output e.g. '0 < 100.00'

Then use this in your function call...

EEGfastrts = pop_selectevent( EEG, 'latency', strLatency, ...
    'type', {'AnyResponse'}, 'renametype', 'FastRTs', ...
    'deleteevents', 'off', 'deleteepochs', 'off', 'invertepochs', 'off');
  • Related