How to solve this error: unexpected MatLab operator
이전 댓글 표시
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
Jos (10584)
2013년 12월 3일
You should also show the code producing the error (line 17 in extract_varargin).
Ali B
2013년 12월 3일
답변 (1개)
Jos (10584)
2013년 12월 3일
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
Ali B
2013년 12월 3일
Ali B
2013년 12월 3일
Jos (10584)
2013년 12월 3일
편집: Jos (10584)
2013년 12월 3일
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
2013년 12월 3일
Jos (10584)
2013년 12월 4일
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.
카테고리
도움말 센터 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!