Azzera filtri
Azzera filtri

generated code will not preserve the expression.

7 visualizzazioni (ultimi 30 giorni)
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 Commento
Walter Roberson
Walter Roberson il 18 Lug 2023
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.

Accedi per commentare.

Risposta accettata

Prathamesh
Prathamesh il 18 Lug 2023
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.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by