Questions about the code of EEGLAB.

The code below is from EEGLAB. Could anyone tell me how the code works?I met a problem when I entered the input of frequency. Is there any limitations?
if ~isempty(varargin)
if ~ischar(varargin{1})
varargin = { varargin{:} [] [] };
if all(varargin{1} > 0)
options = { 'components' varargin{1} 'freqrange' varargin{2} };
else
options = { 'channels' -varargin{1} 'freqrange' varargin{2} };
end
else
options = varargin;
end
else
options = varargin;
end

7 Comments

What error are you experiencing? What values are you passing in?
I
In the frequency column,when I type the number between 8 and 13,error indicating that the number is beyond the range of the array. But when I type the number 1 and 30,it runs well. I am sorry if I didn't explain my problem clearly.
It is unlikely that the code you posted would give an error under those circumstances. Later code in the same function might be responsible.
You should set a breakpoint and examine varargin at the beginning of the code.
Excuse me. Are you familiar with the STUDY Module of EEGLAB?May I bother you with another question about that?
Sorry I am not familiar with that module.
Thank you anyway.
Adam Danz
Adam Danz on 17 Aug 2021
Edited: Adam Danz on 17 Aug 2021
Always share the entire error message when you're asking about an error.
The code you shared is merely setting up options that are likely used as inputs elsewhere in the code. The options depend on what the user provided. You may want to contact the developers of the software for support.

Sign in to comment.

Answers (1)

The code posted exists for backwards compatibility. At present, the primary way of passing in information to the function is by name/value pairs.
But at some point in the past, the code instead had the possibility of passing in two numeric parameters. In the case that the first numeric parameter was entirely positive, then it was to be interpreted as "component" information, and the second parameter was to be interpreted as frequency range information. In the case that the first numeric parameter was negatie, then its negative was to be interpreted as channel selection, and the second parameter was (still) to be interpreted as frequency range information.
The code would mostly have no effect if it was called with name/value pairs. If it was called with numeric values, then Yes, it would have effect -- but the effect of the section posted would be the same for 1 30 as it would be for 8 13.
There could be bugs in later code from the same function. I observe an oddity for a case involving passing in empty arguements, but I suspect that the oddity might be deliberate.

Tags

Asked:

on 17 Aug 2021

Answered:

on 17 Aug 2021

Community Treasure Hunt

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

Start Hunting!