I get a strange error when running my script:
Unable to find function @(x) exp(x) within H:\blabla\myClass.m.
when I debug I get:
34 b=myAnonymousFunction(a)
K>> myAnonymousFunction(3)
Unable to find function @() exp(x) within HH:\blabla\myClass.m.
K>> class(myAnonymousFunction)
ans =
function_handle
A minimal example I was trying to produce worked fine.
Do You have any Idea where the error comes from and what it means? Because he obviously can find the definition of insanity...ahh... myAnonymousFunction. Is it just a bug? I read something on matlabcentral but its 7 Years old and doesn't give an explanation.
Further explanation:
I'm running MATLAB 2012 b under Windows 8 64 bit. The source files were originally written under a 64 bit Linux.
I don't think it's relevant but myAnonymousFunction is a parameter to a function in myClass and stored within a cell array. So it's like this: file myClass.m:
classdef myclass < handle
properties
x=1337;
myAnonymousFunctions;
end
methods
function new = myClass(myAnonymousFunctions)
new.myAnonymousFunction=myAnonymousFunction
end
function show(o)
disp(myAnonymousFunction{1}(o.x));
end
end
end
and gets called like
myMyclass = myClass({@(x)exp(x)})
myMyClass.f();
An anonymous function is a function that is not stored in a program file, but is associated with a variable whose data type is function_handle . Anonymous functions can accept multiple inputs and return one output. They can contain only a single executable statement.
Anonymous functions, also known as closures , allow the creation of functions which have no specified name. They are most useful as the value of callable parameters, but they have many other uses. Anonymous functions are implemented using the Closure class.
Anonymous functions are often arguments being passed to higher-order functions, or used for constructing the result of a higher-order function that needs to return a function. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function.
but anonymous functions are not allowed more than one outputs. This is clearly a simplified example, the application is for a nonlinear programming problem where out1 is the objective function and out2 is the gradient calculation.
Possible Workaround: restart Matlab.
After restarting MATLAB the Problem didn't occur ... so far.
I guess buggy ML debugger was buggy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With