The value returned from getNumInputsImpl method must be a constant value. But the Value is immutable

6 次查看(过去 30 天)
Hi,
i get the following error when generating code:
The value returned from getNumInputsImpl method must be a constant value.
Properties used in calculating this value must be Nontunable.
The error occurred for MATLAB System block 'SiL_LUT_1D/MATLAB System1'.
The method:
function num = getNumInputsImpl(obj)
num = obj.Approx.numInputs + 1; % input
end
The propertie numInputs of Approx(ValueClass):
properties (SetAccess = immutable)
numInputs = 0;
end
And obj.Approx is a nontunable Property of the System block. So for my understanding, this value can't change in anyway and should be interpreted as a constant value. Any suggestion on a fix or workaround?

回答(2 个)

Thomas Kucharczyk
Thomas Kucharczyk 2020-2-26
function num = getNumInputsImpl(obj)
if obj.numInputs ~= obj.Approx.numInputs + 1
obj.numInputs = obj.Approx.numInputs + 1;
end
num = obj.numInputs; % input
end
The above approach with the Nontunable Property "numInputs" will give following error during code generation:
### Starting build procedure for model: SiL_LUT_1D
### Generating code and artifacts to 'Model specific' folder structure
Code Generation 1
Elapsed: 1 sec
### Generating code into build folder: D:\masterarbeit\git\ols-library\Experiment\build\SiL_LUT_1D_ert_rtw
CGIR assertion 'T::isa((const Type*)aType)' failed in 'b:\matlab\src\cg_ir\export\include\cg_ir\type\type.hpp:528'
[ 0] 0x000000055fdc6e8d bin\win64\eml.dll+01011341 EML::COV::registerCoverageListener+00401597
[ 1] 0x000000056015c191 bin\win64\eml.dll+04768145 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00574545
[ 2] 0x00000005601643cd bin\win64\eml.dll+04801485 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00607885
[ 3] 0x00000005601721cd bin\win64\eml.dll+04858317 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00664717
[ 4] 0x000000056006731f bin\win64\eml.dll+03765023 EML::NameCapture::verify+00736239
[ 5] 0x00000005600648ea bin\win64\eml.dll+03754218 EML::NameCapture::verify+00725434
[ 6] 0x0000000560065258 bin\win64\eml.dll+03756632 EML::NameCapture::verify+00727848
[ 7] 0x00000005601b1db4 bin\win64\eml.dll+05119412 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00925812
[ 8] 0x00000005601239a9 bin\win64\eml.dll+04536745 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00343145
[ 9] 0x0000000560130bdd bin\win64\eml.dll+04590557 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00396957
[ 10] 0x0000000560054986 bin\win64\eml.dll+03688838 EML::NameCapture::verify+00660054
[ 11] 0x000000056004e94f bin\win64\eml.dll+03664207 EML::NameCapture::verify+00635423
[ 12] 0x000000056004ed91 bin\win64\eml.dll+03665297 EML::NameCapture::verify+00636513
[ 13] 0x000000056008e194 bin\win64\eml.dll+03924372 EML::NameCapture::verify+00895588
[ 14] 0x00000005601239a9 bin\win64\eml.dll+04536745 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00343145
[ 15] 0x0000000560130bdd bin\win64\eml.dll+04590557 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00396957
### Build procedure for model: 'SiL_LUT_1D' aborted due to an error.
Unexpected or internal error encountered in "in CGIR: b:\matlab\src\cg_ir\export\include\cg_ir\type\type.hpp line 528: T::isa((const Type*)aType)
". Please report this to MathWorks if you can cause it to recur
Component:Simulink | Category:Block diagram error

Honglei Chen
Honglei Chen 2020-2-26
You said numInputs is nontunable, did you try to use Nontunable in the property defintion? Like
properties (Nontunable)
numInputs = 0
end
HTH
  13 个评论
Thomas Kucharczyk
"Code generation does not support assigning an object of a value class into a nontunable property. For example, obj.prop=v; is invalid when prop is a nontunable property and v is an object based on a value class." from MATLAB Classes Definition for Code Generation
This approach shouldn't even start code generation. Maybe there is a check missing for value classes which are set to a property?

请先登录,再进行评论。

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by