user interface - MATLAB GUI - Button Press returning error -


i have simple matlab gui code, find attached. when button pressed runs function.

however when press button twice, throwing error

undefined function 'gui' input arguments of type 'struct'.

error in @(hobject,eventdata)gui('pushbutton1_callback',hobject,eventdata,guidata(hobject))

error while evaluating uicontrol callback

% --- executes on button press in pushbutton1. function pushbutton1_callback(hobject, eventdata, handles) % hobject    handle pushbutton1 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata)  set(handles.pushbutton1, 'enable','off');   output = randomfunction();      = 1  while(1)    = a+1     if == 4          break;      end  end set(handles.pushbutton1, 'enable','on'); 

the issue randomfunction must either change current working directory or modify path such gui function (gui.m) no longer on path , able found when click button second time.

if you'd stop behavior have 2 options

  1. the preferred option modify randomfunction not make modification. function should user's environment way before being called. can using oncleanup within randomfunction

    function randomfunction()     folder = pwd;     cleanup = oncleanup(@()cd(folder));      % normal contents of randomfunction end 

    the other option within randomfunction though never use cd. best practice. can use full file paths instead access files

    filename = fullfile(folder, 'image.png'); imread(filename) 
  2. if can't modify randomfunction can modify callback remember current directory before calling function , change after randomfunction completes. recommend using oncleanup ensure directory changed if randomfunction errors out

    function pushbutton1_callback(hobject, eventdata, handles)     set(handles.pushbutton1, 'enable', 'off');       % make sure when function ends change current folder     folder = pwd;     cleanup = oncleanup(@()cd(folder));      output = randomfunction();      = 1      while(1)        = a+1         if == 4              break;          end      end     set(handles.pushbutton1, 'enable','on'); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -