Why is the EVAL command not able to execute when I pass a java string with variables in it?
Show older comments
Why is the EVAL command not able to execute when I pass a java string with variables in it?
The following code does not work properly
clear foo
jstr=java.lang.String('foo=3;'); % create java string
eval(jstr) % evaluate foo in this (caller) workspace
who foo
The following code generates an error
foo=3;
jstr=java.lang.String('foo*2');
bar=eval(jstr); % BUG!! foo exists but is not found
??? Undefined function or variable 'foo'.
Error in ==> D:\MATLAB6p1\toolbox\matlab\lang\@opaque\eval.m
On line 18 ==> varargout{1:nargout} = eval(tryVal);
Accepted Answer
More Answers (0)
Categories
Find more on Call Java from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!