[英]how to call over values from one function to another using GUIDE?
因此,我尝试使用句柄将创建的数组从回调函数( select_cmp_Callback
,如下所示)调用到创建函数(bot_igntmassflux_1_CreateFcn)。 但是显然所有这些都失败了,并且它Undefined function or variable "cmp_list".
说Undefined function or variable "cmp_list".
提前致谢!
% --- Executes on button press in select_cmp.
function select_cmp_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile({'*.cmp',...
'Component Files (*.cmp)';'*.txt', 'Text Files (*.txt)';...
'*.*','All Files (*.*)'},'Select the Components File'); %add default path
if isequal(FileName,0)
disp('User selected Cancel')
else
disp(['User selected ', fullfile(PathName, FileName)])
copyfile(fullfile(PathName, FileName));
fdd = fopen(FileName);
file_strings = textscan(fdd, '%s', 'Delimiter', ':');
fclose(fdd);
delete(FileName);
file_strings_sz=size(file_strings{1}); %size of file_strings (number of rows)
file_strings_ix=0;
cmp_ix=0;
while file_strings_ix < file_strings_sz(1,1)
file_strings_ix = file_strings_ix+1;
if strcmp(file_strings{1}{file_strings_ix},'COMPONENT')
file_strings_ix = file_strings_ix+1;
cmp_ix=(cmp_ix)+1;
cmp_list{cmp_ix,1} = cellstr(file_strings{1}{file_strings_ix});
file_strings_ix = file_strings_ix+1;
end
end
end
disp(cmp_list);
handles.cmp_list = cmp_list;
function bot_igntmassflux_1_CreateFcn(hObject, eventdata, handles)
cmp_list = handles.cmp_list;
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'String',cmp_list);
结构handles
是一个GUI数据对象。 如果更改它,并希望其他功能访问更新的结构,则必须使用guidata
函数将其存储为新的GUI数据( http://www.mathworks.com/help/matlab/ref/guidata.html )。
如果更新handles
在任何GUI函数的末尾使用以下命令:
guidata(hObject,handles);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.