DSPRelated.com
Forums

nested function in uicontrol callback

Started by Nader June 10, 2009
Hi all,

nested functions do NOT work inside uicontrol callback.
Try this example as an m-file:
%%%%%%%%% start code: function file ttt.m %%%%%%%%%%%%%%%%

function ttt
uicontrol('Style', 'checkbox', 'Units','normalized', ...
'Position', [0.01 0.25 .08 .05],...
'Callback', ['mmm']);

function mmm
x=3
%%%%%% end of code %%%%%%%%%%%%%%%%
Any tip?
I do not want to create an extra m-file!
Thanx a lot ...
Hello,
Well i guess you have to try to make it first working in a separate .m file
and then you try to make it as a nested function.

and remove [ ] from the function name .. and hit it a try again

Regards,
-- A.El-Saeed

On Sun, Jun 7, 2009 at 5:56 PM, Nader wrote:

>
> Hi all,
>
> nested functions do NOT work inside uicontrol callback.
> Try this example as an m-file:
>
> %%%%%%%%% start code: function file ttt.m %%%%%%%%%%%%%%%%
>
> function ttt
> uicontrol('Style', 'checkbox', 'Units','normalized', ...
> 'Position', [0.01 0.25 .08 .05],...
> 'Callback', ['mmm']);
>
> function mmm
> x=3
> %%%%%% end of code %%%%%%%%%%%%%%%%
>
> Any tip?
> I do not want to create an extra m-file!
> Thanx a lot ...
>
>
>
Hello:
You can nest functions but when you use callbacks there is a trick.
Try this code:

/function ttt
uicontrol('Style', 'checkbox', 'Units','normalized', ...
'Position', [0.01 0.25 .08 .05],...
'Callback', @mmm);

function mmm(hObject,eventdata)
x=3
end
end/

Let me know how it works.
Best regards,
Juan
Ahmad El-Saeed wrote:
> Hello,
> Well i guess you have to try to make it first working in a separate .m
> file
> and then you try to make it as a nested function.
>
> and remove [ ] from the function name .. and hit it a try again
>
> Regards,
> -- A.El-Saeed
>
> On Sun, Jun 7, 2009 at 5:56 PM, Nader > > wrote:
>
> >
> >
> >
> > Hi all,
> >
> > nested functions do NOT work inside uicontrol callback.
> > Try this example as an m-file:
> >
> > %%%%%%%%% start code: function file ttt.m %%%%%%%%%%%%%%%%
> >
> > function ttt
> > uicontrol('Style', 'checkbox', 'Units','normalized', ...
> > 'Position', [0.01 0.25 .08 .05],...
> > 'Callback', ['mmm']);
> >
> > function mmm
> > x=3
> > %%%%%% end of code %%%%%%%%%%%%%%%%
> >
> > Any tip?
> > I do not want to create an extra m-file!
> > Thanx a lot ...
> >
> >
> >