generated code will not preserve the expression.

7 次查看(过去 30 天)
I want to save new variable as "Upper Limit " in sldd, which is calculated using the other variables. I don't want to do the mathematical opearation of multiplication instead I am trying to assign the value for upper limit variable as as
"(GRID_NORM_FREQ +(GRID_NORM_FREQ*5/100))*2*PI' "
So I can simulate, but while generating code for the same, I am facing this error.
Parameter object 'Value' property uses an expression '(GRID_NORM_FREQ +
(GRID_NORM_FREQ*5/100))*2*PI' involving division operator. Under this condition, generated code
will not preserve the expression.
  1 个评论
Walter Roberson
Walter Roberson 2023-7-18
I suspect that the division is being replaced by multiplication by a reciprical -- that GRID_NORM_FREQ*5/100 is going to have code generated as if it were GRID_NORM_FREQ*5*0.01 . That might not generate exactly the same results
Also remember that when you code something like A * 2 * Pi then each element of A would be multiplied by 2 and the result would be multiplied by Pi for a total of numel(A) times 2 multiplications -- MATLAB is not certain to optimize it to A*(2*Pi) which would be numel(A)+1 multiplications.

请先登录,再进行评论。

采纳的回答

Prathamesh
Prathamesh 2023-7-18
Hi,
I understand that you are encountering the error message ‘generated code will not preserve the expression’
For the generated code to preserve the expression other than auto theDataType property of the object that uses the expression should be set to the same value. Otherwise, the code generator does not preserve the expression.
Here the expression "(GRID_NORM_FREQ +(GRID_NORM_FREQ*5/100)) *2*PI' " is not producing the value with same ‘DataType’ due to presence of division operator.
You can try to typecast the whole expression in same DataType’.
For example, if the output is expected to be a ‘single’ value then typecast the expression in single,
single((GRID_NORM_FREQ +(GRID_NORM_FREQ*5/100)) *2*PI')
For more information you can refer to the documentation attached below.
I hope this resolves you issue.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by