eval([ans '=' num2str(x0(i)) ';']); gives an error "The expression to the left of the equals sign is not a valid target for an assignment". what could be the problem?
Ältere Kommentare anzeigen
eval([ans '=' num2str(x0(i)) ';']); gives an error "The expression to the left of the equals sign is not a valid target for an assignment". what could be the problem?
1 Kommentar
Stephen23
am 8 Nov. 2017
Avoid using eval for such trivial code:
Antworten (2)
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.
Mischa Kim
am 8 Nov. 2017
Just wondering if the following would do the trick...
eval('ans = num2str(x0(i));')
4 Kommentare
Why bother? There does not seem to be anything here that requires using the chainsaw eval. Why not just
X = num2str(x0(i));
???
Mischa Kim
am 8 Nov. 2017
I do not have enough information here to judge what is required and what is not. The question posed contains one single command.
Balaji Jayaraman
am 8 Nov. 2017
Adam
am 8 Nov. 2017
Most of that code appears to do nothing or create variables that nothing is done with!
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!