You are getting these errors because MATLAB does not support code generation for all the function. The supported function list ishere. Also, there are several restrictions for code generation forfunction handle. The easiest way to solve this problem is to move all of your code from Simulink function block to a MATLAB function file and save it in MATLAB path. Then define these functions asextrensic as shown on this link:https://www.mathworks.com/help/simulink/ug/calling-matlab-functions.html. Simulink will not try to generate code for the extrensic functions and simulation will run.