Error using evalin Undefined function or variable 'var'.
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Voss
le 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 commentaire
Samuel Jesus
le 9 Mar 2023
Catégories
En savoir plus sur Argument Definitions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!