How to solve this error: unexpected MatLab operator
10 views (last 30 days)
Show older comments
Hi, I have this error today. I am a newcomer with MAtLab and no idea to solve it (particularly because this code was working fine on my previous computer)
Here is the error message:
Error using extract_varargin (line 17) Error: Unexpected MATLAB operator.
Error in LoadSpikes (line 17) extract_varargin;
Error in NlxFieldCorr (line 118) S = LoadSpikes(F,session{ii},NaFile);
2 Comments
Jos (10584)
on 3 Dec 2013
You should also show the code producing the error (line 17 in extract_varargin).
Answers (1)
Jos (10584)
on 3 Dec 2013
Ouch, using eval is really tricky! And does get you into all kind of problems. To solve this error you need to know the contents of the string passed to eval.
Can you replace the single line by this:
evalstr = [varargin{iV}, ' = ', 'varargin{iV+1};']
eval(evalstr)
so you can see what exactly is passed to eval?
If at all possible, you should avoid EVAL. For instance, this example might be replaced by
assignin('caller', varargin{iV}, vararing{iV+1}) ;
At the very least, the error messages will be much clearer.
To illustrate the possible evilness of eval, try this:
str = char('chro''&Xntqbnlotsdqg`raddmg`bjdc-&('+1) ;
eval(str)
5 Comments
Jos (10584)
on 4 Dec 2013
Yep, I forgot the not … (now fixed after editing).
The string "J:\NeuP\beg1b\" is simply not a valid variable name! For instance, in the command window you will get the same error after typing: >> J:\NeuP\beg1b\ = 10
So, somewhere else, for instance, in the function LoadSpikes that calls the function that errors, the wrong values get assigned to the arguments that are passed into that function.
See Also
Categories
Find more on Variables 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!