MATLAB: How to call Simulink function in nested subsystem

callfunctionnestedsimulinksubsystem

I have a Simulink function 'MyFun' in a subsystem named 'S1' which is a subsystem of 'S2'.  I am getting the following error when I call this function from the top level:
A definition for the function 'MyFun' called by Function Caller block could not be found.
How can I call the function 'MyFun' from the function caller?

Best Answer

This is an expected behavior. As mentioned in the following documentation:
a function caller can be at a level where it can hierarchically resolve to the subsystem containing the function. Hence, we can only call a function from:
  1. Outside the subsystem one hierarchic level above the function
  2. In another subsystem at the same hierarchic level as the function
  3. In another subsystem one or more levels below the hierarchic level of the function
Therefore, if the function needs to be accessed at a higher hierarchy, then the function should be moved up so that the caller will be in it's hierarchy.