Preventing parallel GUI functions from overrunning matlab

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?

 채택된 답변

Joseph Cheng
Joseph Cheng 2014년 6월 9일
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

댓글 수: 2

Charles Miller
Charles Miller 2014년 6월 10일
편집: Charles Miller 2014년 6월 10일
This works perfectly, I forgot about the enable property, Thanks!
edit: Actually, in the event that I need to use the function for a variable set of pushbuttons or conditions, it would be nice if the function simply didn't allow itself to be called again
In that case, you could at the beginning of the function have a FLAG check to see if it should run again or not. However i do not exactly know if you can get that flag updated while another instance of the function is being run such that the second instance has an update. When i get the chance i'll run a test and get back to you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

per isakson
per isakson 2014년 6월 9일
편집: per isakson 2014년 6월 10일
Interruptible
{on} | off
Callback routine interruption mode. Controls whether a object
callback function can be interrupted by subsequently invoked
callbacks.
.
In response to comments:
.
Try
uicontrol( 'Callback', 'interrupt_test' ...
, 'Interruptible', 'off' ...
, 'BusyAction', 'queue' )
and
uicontrol( 'Callback', 'interrupt_test' ...
, 'Interruptible', 'off' ...
, 'BusyAction', 'cancel' )
where
function interrupt_test
fprintf('responding at: %s\n', datestr( now, 'MM:SS.FFF') )
pause( 2 )
end

댓글 수: 3

Wouldn't this property be set to on by default?
AHH
set(gco,'interruptible','off') would prevent subsequent functions being called, assuming it's called from an object, which might be the problem.
per isakson
per isakson 2014년 6월 10일
편집: per isakson 2014년 6월 10일
"which might be the problem" . What problem do you refer to?
I added an example to my answer

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2014년 6월 9일

댓글:

2014년 6월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by