I have a complicated function that take awhile to run. I
have set up a GUI using GUIDE to handle different variables.
The problem I have is the user can click the run button, or
a slider control multiple times. This calls multiple
instances of the function, with bizarre results. In a
couple cases enough functions are called to crash Matlab.
I tried making the waitbar() modal. However, you can still
sneak in 2-3 button presses. Even worse, if you click a
slider control it locks and then proceeds to repeatedly push
the slider button (calling a function instance every time)
until it reaches the max limit!!!
I'm pretty sure the following code will work:
set(hObject, 'Enable', 'off')
set(handles.lblWait, 'String', 'Thinking ...')
pause(0.01)
fcnTestPlot(fVal, handles); % <-- this is "long" fcn
"Adam " <not.my.email@mathworks.com> wrote in message
news:fc71me$ouq$1@fred.mathworks.com...
>I have a complicated function that take awhile to run. I
> have set up a GUI using GUIDE to handle different variables.
> The problem I have is the user can click the run button, or
> a slider control multiple times. This calls multiple
> instances of the function, with bizarre results. In a
> couple cases enough functions are called to crash Matlab.
>
> I tried making the waitbar() modal. However, you can still
> sneak in 2-3 button presses. Even worse, if you click a
> slider control it locks and then proceeds to repeatedly push
> the slider button (calling a function instance every time)
> until it reaches the max limit!!!
*snip*
Read this section from the documentation that discusses Callback
Interruption:
Note this is from the MATLAB 7.5 (R2007b) documentation, but I don't believe
there was any change in this functionality from MATLAB 7.4 (R2007a) to 7.5.
--
Steve Lord
slord@mathworks.com
Subject: Re: Tempoarily Disable a GUI while a function is running
"Adam " <not.my.email@mathworks.com> wrote in message
<fc71me$ouq$1@fred.mathworks.com>...
> I have a complicated function that take awhile to run. I
> have set up a GUI using GUIDE to handle different variables.
> The problem I have is the user can click the run button, or
> a slider control multiple times. This calls multiple
> instances of the function, with bizarre results. In a
> couple cases enough functions are called to crash Matlab.
>
> I tried making the waitbar() modal. However, you can still
> sneak in 2-3 button presses. Even worse, if you click a
> slider control it locks and then proceeds to repeatedly push
> the slider button (calling a function instance every time)
> until it reaches the max limit!!!
>
> I'm pretty sure the following code will work:
> set(hObject, 'Enable', 'off')
>
> set(handles.lblWait, 'String', 'Thinking ...')
> pause(0.01)
> fcnTestPlot(fVal, handles); % <-- this is "long" fcn
>
> pause(0.01)
> set(handles.lblWait, 'String', '')
> set(hObject, 'Enable', 'on')
>
> It seems like a bit of a hack; i.e. is there a better way?
You might wish to use my "enable/disable figure" submission
on the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15895
- it disables the entire figure, as well as all contained UI
controls and menus, in a single command. After your callback
function ends, you can call this function again to re-enable
the figure.
"Steven Lord" <slord@mathworks.com> wrote in message
<fc7qds$6pt$1@fred.mathworks.com>...
>
> "Adam " <not.my.email@mathworks.com> wrote in message
> news:fc71me$ouq$1@fred.mathworks.com...
> >I have a complicated function that take awhile to run. I
> > have set up a GUI using GUIDE to handle different variables.
> > The problem I have is the user can click the run button, or
> > a slider control multiple times. This calls multiple
> > instances of the function, with bizarre results. In a
> > couple cases enough functions are called to crash Matlab.
> >
> > I tried making the waitbar() modal. However, you can still
> > sneak in 2-3 button presses. Even worse, if you click a
> > slider control it locks and then proceeds to repeatedly push
> > the slider button (calling a function instance every time)
> > until it reaches the max limit!!!
>
> *snip*
>
> Read this section from the documentation that discusses
Callback
> Interruption:
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/creating_guis/bq61qtj-1.html
>
> Note this is from the MATLAB 7.5 (R2007b) documentation,
but I don't believe
> there was any change in this functionality from MATLAB 7.4
(R2007a) to 7.5.
>
> --
> Steve Lord
> slord@mathworks.com
so a dialog box doesn't automatically set Interruptible to
'off' and BusyAction to 'cancel'. However, setting these
properties has no effect. Please run this code, and click
on the left, slider button.
What am I missing?
Also, callback_interrupt.m didn't come with my matlab
installation.
% --- begin code -------------------------------------------
function testCallback()
cellName = {'BusyAction', 'Interruptible'};
cellValue = { 'cancel', 'off'};
"Adam " <not.my.email@mathworks.com> wrote in message
<fc71me$ouq$1@fred.mathworks.com>...
> I have a complicated function that take awhile to run. I
> have set up a GUI using GUIDE to handle different
variables.
> The problem I have is the user can click the run button,
or
> a slider control multiple times. This calls multiple
> instances of the function, with bizarre results. In a
> couple cases enough functions are called to crash Matlab.
>
> I tried making the waitbar() modal. However, you can
still
> sneak in 2-3 button presses. Even worse, if you click a
> slider control it locks and then proceeds to repeatedly
push
> the slider button (calling a function instance every time)
> until it reaches the max limit!!!
>
> I'm pretty sure the following code will work:
> set(hObject, 'Enable', 'off')
>
> set(handles.lblWait, 'String', 'Thinking ...')
> pause(0.01)
> fcnTestPlot(fVal, handles); % <-- this is "long" fcn
>
> pause(0.01)
> set(handles.lblWait, 'String', '')
> set(hObject, 'Enable', 'on')
>
> It seems like a bit of a hack; i.e. is there a better
way?
Yes, this is bizarre. I don't understand what is going on,
but I don't think fcnRun is called multiple times.
I tried this variant, which I think works
function y = fcnRun( hObject, eventdata ) %#ok<INUSD>
ii = ii + 1; % ii=1; in the outer function
fprintf( '%i', ii )
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.