Hi,
I am trying ultimately to be able to define a new anonymous function from two previously defined functions, and pass this into a function. Say, for simplicity, I define:
then I try to define:
then this works. I can put in values of d and c and get (d^2)*(c^c) as an output from E. I am trying to understand how MATLAB defines the new function E. If I delete functions D and C from the workspace, and continue to call E(1,2) etc then E will continue to produce results, so it's as if MATLAB has stored C and D inside E itself.
However, if I pass E into a new function and ask it to calculate E(1,2) inside there - I get an error. (Undefined function or method 'mtimes' for input arguments of type 'function_handle'). So it's as if MATLAB has now forgotten D and C, so they are not built into E.
Can someone explain what is happening here? I'm just trying to grasp how these functions are working.
Thanks!
1 Comment
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/67618-multiple-anonymous-functions-combined#comment_137259
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/67618-multiple-anonymous-functions-combined#comment_137259
Sign in to comment.