[Eeglablist] Characters vs Strings in MATLAB and EEGLAB

Dr Cyril, Pernet wamcyril at gmail.com
Sun Jun 11 23:59:09 PDT 2023


Hi James,

> Hello Folks,
> I'm currently learning MATLAB and EEGLAB with the goal of writing scripts to automate data processing.
Just in case you are not aware of this ... use the GUI then check 
EEG.history and it tells you what function and argument were used (= 
make a loop over subject and copy paste)
> I'm aware that you can use character and string arrays in MATLAB.
> chardoge = 'doge' % This creates a 1x4 character vector.
> stringdoge = "doge" % However, this creates a 1x1 string vector.
> I noticed you can also pass in arguments to functions using either single or double quotes.
> NumArray = [2 5 9 ; 1 3 7 ; 6 4 8]
> mean(NumArray,"all")
> mean(NumArray,'all')
> Both calls return an answer of 5.
> Is it better to use character or string arrays when working with EEGLAB?

following MathWorks recommendations char is good for number/vector like 
computation while string is better for arrays you want to work with 
(like making tables) -- for instance, you could organize your data using 
BIDS 
(https://urldefense.com/v3/__https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/03-electroencephalography.html__;!!Mih3wA!ALqIIXVnAk80vIAUYM2mUBOTr7JYAVuqi_Y1ntpvRfjtKcCbG_Oki632Cp2P1JKlZPfvHwJswUlP3rL5EE29KA$ ) 
and when importing all at once using EEGLAB bids tool (via the plugin 
manager --> plugin_askinstall('bids-matlab-tools',[],1);). All the text 
information is parsed as char (for cleaning) and converted as string 
because we want to work on them - the STUDY that is build automatically 
that way contains various strings meaning you can then filter trials 
'textually' and build a statistical model easily.

> As for passing in arguments that require quotes, I'm assuming it doesn't matter if I use single or double quotes.

that's correct

Cyril





More information about the eeglablist mailing list