MATLAB: MATLAB GUIDE and compiler

guideMATLAB Compiler

I have written a very simple program using MATLAB GUIDE. I display 2 pushbuttons. When the user clicks the first pushbutton, the text "hello" appears on the console. When the user clicks the second pushbutton, the text "goodbye" appears on the console. I chose to separate the two functions pushbutton1_Callback and pushbutton2_Callback into separate .m files within the same directory as the main program. Everything works fine. Next, I compiled the program using the MATLAB compiler. When I tried to execute the compiled program, I get the error message, 'undefined function pushbutton1_Callback'. I can fix this error by taking pushbutton1_Callback and pushbutton2_Callback code and placing it back into the main program (all code in the same file instead of in separate files). What's going on? Is it a mistake to put gui functions into separate files? I'm also puzzled because if the compiler doesn't allow this, why wouldn't the error be flagged during compilation? With longer programs (thousands of lines), the program will compile but give me erroneous results (e.g. when I click on one pushbutton it will execute the code which appears under another pushbutton)
For the simple case, I've pasted in pushbutton1_Callback code below. Main program code is created entirely by GUIDE.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(sprintf('hello_2'));

Best Answer

Insert this somewhere in your main file (e.g., the first line in the opening function)
%#function pushbutton1_Callback pushbutton2_Callback
and recompile and see if it makes a difference.