Division in stateflow is showing only integer part
Afficher commentaires plus anciens
I am trying to do a simple division operation in stateflow like a=5/2 but the output is coming to 2 instead of 2.5 The data type of a is double. Its rounding the decimal digits and giving me only the integer part. Pls help
1 commentaire
Vishal Rane
le 15 Mar 2013
Just noticed that using 5.0/2.0 instead of 5/2 gives you 2.5.
Réponses (3)
Vishal Rane
le 15 Mar 2013
Modifié(e) : Vishal Rane
le 15 Mar 2013
I believe typecasting both dividend and divisor as double should do the job.
{
a = double(5)/double(2);
}
Not sure whether this the usual approach.
1 commentaire
Aditya
le 16 Mar 2013
Aditya
le 19 Mar 2013
0 votes
chaitanya balaga
le 20 Nov 2019
Modifié(e) : chaitanya balaga
le 20 Nov 2019
0 votes
Instead, you can try the following assignment, a:=5/2;
This overrides the floor(a/b) behaviour in stateflow and gives you the desired result which is entirely dependent on the datatype of a. In this case you will get a = 2.5
Catégories
En savoir plus sur Simulink Functions dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!