Unknown Output Type for coder.ceval
Issue
You see this error message:
Output of 'coder.ceval' has unknown type. The enclosing expression cannot be evaluated. Specify the output type by assigning the output of 'coder.ceval' to a variable with a known type.
Cause
This error message occurs when the code generator cannot determine the output type of acoder.ceval
call.
Solution
Initialize a temporary variable with the expected output type. Assign the output ofcoder.ceval
to this variable.
Example
Assume that you have a C function calledcFunctionThatReturnsDouble
. You want to generate C library code for a functionfoo
. The code generator returns the error message because it cannot determine the return type ofcoder.ceval
.
functionfoo%#codegencallFunction(coder.ceval('cFunctionThatReturnsDouble'));endfunctioncallFunction(~)end
To fix the error, define the type of the C function output by using a temporary variable.
functionfoo%#codegentemp = 0; temp = coder.ceval('cFunctionThatReturnsDouble'); callFunction(temp);endfunctioncallFunction(~)end
You can also usecoder.opaque
to initialize the temporary variable.
Example Using Classes
假设您有一个类和一个定制的set
method. This class uses theset
method to ensure that the object property value falls within a certain range.
classdefclassWithSetterpropertiesexpectedResult = []endproperties(Constant) scalingFactor = 0.001endmethodsfunctionobj = set.expectedResult(obj,erIn)iferIn >= 0 && erIn <= 100 erIn = erIn.*obj.scalingFactor; obj.expectedResult = erIn;elseobj.expectedResult = NaN;endendendend
When generating C library code for the functionfoo
, the code generator produces the error message. The input type into theset
method cannot be determined.
functionfoo%#codegenobj = classWithSetter; obj.expectedResult = coder.ceval('cFunctionThatReturnsDouble');end
To fix the error, initialize a temporary variable with a known type. For this example, use a type of scalar double.
functionfoo%#codegenobj = classWithSetter; temp = 0; temp = coder.ceval('cFunctionThatReturnsDouble'); obj.expectedResult = temp;end