MATLAB: Accessing value of toggle button in GUIDE

guidehandle

I made a GUI in GUIDE, and ran into what seems like a simple issue, but I can't figure out what I'm overlooking.
I have an "execute" push button, which when pressed, checks the state of a "frequency plot" toggle button. If "frequency plot" button is active, a function to plot some data runs.
Inside the plotting function, I have:
if get(handles.toggle1,'Value')==1
fdata{1,1}=...
fdata{1,2}=...
end
I do this because the data can be used for different plots, and might not necessarily be used in this case. This is controlled by a toggle button. If the button is active, I add the data to a cell which is plotted.
I get the error: ??? Undefined variable "handles" or class "handles.toggle1".
I can't figure out why. I use this same line with set elsewhere in the program (not this function) and it access it fine.

Best Answer

Is handles being passed in to the plotting function?
Is the toggle button being created dynamically, or was it created statically and is part of your stored .fig file ?