簡體   English   中英

如何使用GUIDE從一個函數調用另一個函數的值?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM