How to solve this error: unexpected MatLab operator
Afficher commentaires plus anciens
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 commentaires
Jos (10584)
le 3 Déc 2013
You should also show the code producing the error (line 17 in extract_varargin).
Ali B
le 3 Déc 2013
Réponses (1)
Jos (10584)
le 3 Déc 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 commentaires
Ali B
le 3 Déc 2013
Ali B
le 3 Déc 2013
Jos (10584)
le 3 Déc 2013
Modifié(e) : Jos (10584)
le 3 Déc 2013
This last error gives you the answer. What you pass into the function "extract_varargin" using varargin does represent a valid variable name.
Ali B
le 3 Déc 2013
Jos (10584)
le 4 Déc 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.
Catégories
En savoir plus sur Argument Definitions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!