所以我尝试使用句柄从一个回调函数(select_cmp_Callback
)调用一个已创建的数组,如下所示)到一个create函数(bot_igntmassflux_1_CreateFcn)。
但显然所有失败的事情都在继续说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);
答案 0 :(得分:0)
struct handles
是一个GUI数据对象。如果您更改它,并希望其他函数访问更新的结构,则必须使用guidata
函数(http://www.mathworks.com/help/matlab/ref/guidata.html)将其存储为新的GUI数据。
如果更新handles
:
guidata(hObject,handles);