0

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);
wasnt here
  • 11
  • 4

1 Answers1

0

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);
ThP
  • 2,312
  • 4
  • 19
  • 25
  • I am sorry but I tried looking at that and doing it myself but still does not make much sense... Do you mind explaining a bit more? – wasnt here Dec 24 '14 at 20:37
  • First, you should add the command at the last line of `select_cmp_Callback`. In any case, I believe that `bot_igntmassflux_1_CreateFcn` is called when the GUI is opened so I don't quite understand what you are trying to do... – ThP Dec 24 '14 at 20:51
  • Oh soo i am trying to add options that cmp_list has in the createfcn when it is selected. But i am still going through the same error – wasnt here Dec 24 '14 at 20:54