MATLAB: Preventing parallel GUI functions from overrunning matlab

breakfunctionsguimatlab guiparallel functionsreturn

Hello! I've run into a brick wall, and I believe that it's because I don't understand how matlab handles parallel functions.
First of all, lets say that I have a GUI with a single button in the middle
figure1 = figure; button1 = uicontrol('style','pushbutton','position',[.5 .5 .5 .5]);
And lets say that this button's callback function opens up a new figure to say, change the color of the figure background with another function that I've written.
set(button1,'callback',@changeBkgrdColor)
Now, if the user clicks on the button again without ending the changebkgrdColor function, it'll open up a second instance of my changeBkgrdColor function.
If you're looking to crash matlab, you can open up about 30 parallel functions and from that point, no more functions will open, matlab freaks, and the only way to fix it is to ctrl+c on the command line or end matlab's process.
Is there a way to break out of a function with something like a handle reference?

Best Answer

Well what you can do to stop this from happening is to deactivate the pushbutton until the the function is completed.
function testing()
myvar = 5;
figure
uicontrol('Style','pushbutton','String','new','Callback',{@pushbutton_callback,myvar});
end
function pushbutton_callback(hObject,eventdata,x)
set(hObject,'Enable','off')
figure,plot(rand(x));
pause(10)
set(hObject,'Enable','on')
end
http://www.mathworks.com/matlabcentral/newsreader/view_thread/246447 speaks to what you are trying to do look for in the breaking out of a running function. I do not think it can readily be done.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/286204 does mention something but it all depends on your implementations
Related Question