Error using evalin Undefined function or variable 'var'.
Show older comments
Hello all!
I'm trying to figure out why I keep getting the error: Undefined function or variable 'var'.
Here's my code:
function Port_callback(varargin)
GUI=varargin{numel(varargin)};
var=string(get(GUI.ed(1),'String'));
fprintf('Inserted USB Port: %s\n',var);
evalin('base',"Port=var;");
end
The string in var is printed to the command prompt using fprintf, however in the next line of code i keep getting the error undefined variable 'var'.
Any ideas on why this error keeps occurring?
Accepted Answer
More Answers (1)
Voss
on 9 Mar 2023
This line
evalin('base',"Port=var;");
evaluates "Port=var;" in the base workspace. Apparently you don't have a variable called "var" in the base workspace.
If you want to have a variable "Port" in your base workspace with the value of "var" that is in the Port_callback workspace, you can
assignin('base','Port',var);
1 Comment
Samuel Jesus
on 9 Mar 2023
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!