简体   繁体   English

如何使用GUIDE从一个函数调用另一个函数的值?

[英]how to call over values from one function to another using GUIDE?

So I try to use handles to call over a created array from a callback function ( select_cmp_Callback ), shown below) to a create function (bot_igntmassflux_1_CreateFcn). 因此,我尝试使用句柄将创建的数组从回调函数( select_cmp_Callback ,如下所示)调用到创建函数(bot_igntmassflux_1_CreateFcn)。 But apparently all that failed and it keep saying Undefined function or variable "cmp_list". 但是显然所有这些都失败了,并且它Undefined function or variable "cmp_list".Undefined function or variable "cmp_list".

thanks in advance! 提前致谢!

% --- 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);

The struct handles is a GUI data object. 结构handles是一个GUI数据对象。 If you change it, and want other functions to access the updated struct, you have to store it as the new GUI data by using the guidata function ( http://www.mathworks.com/help/matlab/ref/guidata.html ). 如果更改它,并希望其他功能访问更新的结构,则必须使用guidata函数将其存储为新的GUI数据( http://www.mathworks.com/help/matlab/ref/guidata.html )。
Use the following command in the end of any GUI function if you update handles : 如果更新handles在任何GUI函数的末尾使用以下命令:

guidata(hObject,handles);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM