Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can matlab be unable to find an anonymous function?

Tags:

matlab

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();
like image 252
jan-glx Avatar asked Mar 24 '13 16:03

jan-glx


People also ask

How does anonymous function work in Matlab?

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.

How do you make an anonymous function?

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.

When would you use an anonymous function?

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.

Can anonymous function have multiple outputs Matlab?

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.


1 Answers

Possible Workaround: restart Matlab.

After restarting MATLAB the Problem didn't occur ... so far.

I guess buggy ML debugger was buggy.

like image 136
jan-glx Avatar answered Oct 01 '22 20:10

jan-glx