Error using evalin Undefined function or variable 'var'.
古いコメントを表示
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?
採用された回答
その他の回答 (1 件)
Voss
2023 年 3 月 9 日
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);
カテゴリ
ヘルプ センター および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!