How do i use str2func for methods within a class?
Show older comments
I have a class with several functions. Now I want to write a new function within this class that has an string as an input. This string is an actual function name that is defined within that same class. The new function has to convert this string to the function handle and run this particular function. I tried to do this conversion using str2func, however it doesnt recognize the function: Undefined function or variable 'obj.calcMassMatrixTot'.. However, when I try a global Matlab function such as rand, it works. So it looks like str2func can only see functions that are defined globally. How should I approach this problem?
edit: it might be important to note that im creating the function handle in a function within a different class.
edit2: solved it by moving the new function to the class where i am running all the functions. Still i wonder how i could make the right function handle.
Accepted Answer
More Answers (0)
Categories
Find more on Function Handles in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!