MATLAB: GUI Call back Function Error!

callbackgui

Im trying to create a button that prompts user to select file to load and display.
function loadbutton_Callback(hObject, eventdata, handles)
[datafile datadir] = uigetfile('*.csv');
end
When I run this code on a separate file it works but when I added to my code it gives this error
*Function definitions are not permitted in this context.*

Best Answer

What version of Matlab are you using?
I'm guessing you are not in the latest and your main file is a script which does not allow subfunctions.
Just change your script into a function by adding
function myMFilename( )
at the top, obviously replacing myMFilename with whatever is the name of your file.
or move this function into a file of its own somewhere on your path.
Related Question