Muh*_*sif 3 matlab user-interface
我在MATLAB工作区中有一个变量,我想将这个变量传递给我的GUI中的一个函数.
我该如何完成这项任务?
您可以在GUI中使用EVALIN函数从基础工作区获取变量的值.以下示例提取A基础工作空间中变量的值,并将该值放在局部变量中B:
B = evalin('base','A');
Run Code Online (Sandbox Code Playgroud)
例如,您可以在GUI中有一个可编辑的文本框,允许用户输入要从基础工作区导入的变量的名称.然后,您的一个GUI函数可以从可编辑文本框中读取字符串,并尝试从基础工作区获取该变量以用于某些计算:
varName = get(hEditText,'String'); %# Get the string value from the uicontrol
%# object with handle hEditText
try %# Make an attempt to...
varValue = evalin('base',varName); %# get the value from the base workspace
catch exception %# Catch the exception if the above fails
error(['Variable ''' varName ... %# Throw an error
''' doesn''t exist in workspace.']);
end
Run Code Online (Sandbox Code Playgroud)