Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Constructing Function Handles

0 views
Skip to first unread message

Daniel

unread,
Dec 9, 2009, 8:49:25 AM12/9/09
to
Hello,

I have a function like the following:

function FHandle = myFunction

FHandle = @mySubFunction;

function mySubFunction

Now I can get the function Handle of the Subfunction by simply calling the myFunction and call the mySubFunction from outside the function.
The Properties are stored within the FunctionHandle itself which you can get by functions(FHandle)
So far so well

No I want to create such a FunctionHandle for a Subfunction from outside the function. Wit ohter word I want to edit the properties i can see with the functions-command.
Does anybody know a way to do that?

Regards
Lord nibbler

Steven Lord

unread,
Dec 9, 2009, 9:47:28 AM12/9/09
to

"Daniel" <Daniel....@gmx.de> wrote in message
news:1451318942.29794.12603...@gallium.mathforum.org...

> Hello,
>
> I have a function like the following:
>
> function FHandle = myFunction
>
> FHandle = @mySubFunction;
>
> function mySubFunction
>
> Now I can get the function Handle of the Subfunction by simply calling the
> myFunction and call the mySubFunction from outside the function.
> The Properties are stored within the FunctionHandle itself which you can
> get by functions(FHandle)

Those aren't really properties in the object-oriented, "I can set and get
them", sense. They're simply information about the function handle.

> So far so well
>
> No I want to create such a FunctionHandle for a Subfunction from outside
> the function. Wit ohter word I want to edit the properties i can see with
> the functions-command.
> Does anybody know a way to do that?

You can't do either of these. The subfunction is only in scope inside the
file in which it is defined, since it's not the main function in that file.
Therefore attempting to create a function handle to a function of that name
will either not work (if no function of that name is in scope when the
function handle is created) or will refer to a function that's in scope.
[That description is a _little_ bit of a simplification, but it's close
enough for purposes of this post.] You cannot modify the information
displayed by the FUNCTIONS command either (well, if you called FUNCTIONS
with an output argument you could, but that wouldn't change the function
handle.)

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


Daniel

unread,
Dec 10, 2009, 3:20:37 AM12/10/09
to
Hi Steve,
Thank you for your fast reply, even it is not the answer I wanted to hear.
Some background information: Im writing a program for testing automatically matlab GUIs. Therefore I'm searching the GUI-Figure for uicontrols with a callback and save all information to execute the callback even after deleting and restarting the GUI. This works fine if I save the callback (and other data) within a mat-File. But I need to save the TestCases in an xml-File in which I just can define Strings (or doubles transformed to a string or someting similar). If I store the FunctionHandle as a String and reconstruct a FunctionHandle from this string (str2func) the information about the focus and file in which the callback is used is lost.
Its just annoying, that I could store all relevant information, but couldn't construct a FunctionHandle with this information.
So it seems that it can't be done and I have to think of a different solution.

Best regards
Daniel G

0 new messages