MATLAB: How to slice inside GUI without error feval(varargin{:})

arraysMATLABmatlab guislicing

So I am making a GUI using GUIDE. The first step I want to make is to reduce my 11D array dataset to a 3D array. This is no problem normally, I just slice it like data(:,:,1,:,1,1). However when I let a UI element call that as in tempdat = data(:,:,1,:,1,1) I receive the error :
Undefined function or variable 'handles'.
Error in simple>slider2_Callback (line 194)
image(handles.data(1:handles.rows,1:handles.cols, temp));
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in simple (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)simple('slider2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I have tried many other ways to get the colon in there, but I always get stuck on an error. The above error is the error of one of my tries. The thing all errors have in common is the "Error in gui_mainfcn (line 96) feval(varargin{:});" part. When I check for handles it does exist. How to slice in GUI? I dont understand why it does not work. Is this really a problem with the colon or is it more likely something else?

Best Answer

A likely culprit is that you copied and pasted some test script into your callback function and you used "clear all" in the script. You MUST get rid of clears when you transfer code because that will blow away all variables, including the essential "handles" variable. Please search your entire code for the word clear.