fminsearch in Matlab classes for code generation

I am designing a Matlab class to do some optimization and I am using fminsearch. I want to put it into a user-defined Matlab function in Simulink. I know the anonymous functions have issues with code generation so I constructed the objective function as a class method so I can avoid using the anonymous function. Then, I ended up with something like fminsearch(@obj.objFunc,x,options). Everything works fine in a little unit test I wrote in Matlab script. However, after I put it into the user-defined Matlab function in Simulink, it complains that "code generation does not support function handles pointing to non-static methods." I cannot change the attribute of my objective function into "static", since it requires the information of other variables of the class properties. So how I can use fminsearch in a Matlab class with code generation? Thanks.

回答 (1 件)

質問済み:

ZK
2016 年 11 月 17 日

回答済み:

2021 年 5 月 31 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by