There are many thing wrong with
eval([ans '=' num2str(x0(i)) ';'])
- eval expect a string or char array. As per Mischa's answer the whole expression probably needs to be enclosed in quote.
- do not use ans as a variable name. It's a special variable used by matlab.
- and worst of all, is the use of eval. There's normally very little reason to use eval, in the above case, there's absolutely no reason, other than making the code harder to debug, more difficult to read and obviously harder to use since you can't get the syntax right
SomeVariableNameOtherThanANS = num2str(xi(0));
would do exactly the same.
댓글 수: 1
Stephen Cobeldick (view profile)
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/365801-eval-ans-num2str-x0-i-gives-an-error-the-expression-to-the-left-of-the-equals-sign-is#comment_502460
로그인 to comment.