tags:

views:

24

answers:

1

I have a rather complicated function the I would like to write as an anonymous function.

It looks something like this:

function Answer = MatlabFunction(x)
a=4*x;
b=sin(a);
c=cos(b);
Answer = c;

I don't know how to put this into an anonymous function however. Is there a way to do this without writing it as several cascading functions?

+2  A: 

There are two ways:

Either, you save your function MatlabFunction on the Matlab path, and define your anonymous function as

myFun = @MatlabFunction;

Or, you define the function directly as

myFun = @(x)cos(sin(4*x));
Jonas
Is there a different way? I want to set the function want to change parts of the function at each cycle in a for loop, so I can't use an external file. My actual function is much more complicated so I can't just combine it into one line.
Brian
@Brian: I answered your other question here: http://stackoverflow.com/questions/3673112/change-matlab-function-in-loop/3673185#3673185
Jonas
You could pass several arbitrary chosen function handles to your 'worker' function.
zellus

related questions