Effacer les filtres
Effacer les filtres

generated code will not preserve the expression.

7 vues (au cours des 30 derniers jours)
Jaya Mane
Jaya Mane le 23 Juin 2023
Commenté : Jaya Mane le 6 Déc 2023
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 commentaire
Walter Roberson
Walter Roberson le 18 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Prathamesh
Prathamesh le 18 Juil 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.
  1 commentaire
Jaya Mane
Jaya Mane le 6 Déc 2023
Thanks Prathamesh, this solved my issue.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by