简体   繁体   中英

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). But apparently all that failed and it keep saying 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. 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 ).
Use the following command in the end of any GUI function if you update handles :

guidata(hObject,handles);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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