how can i make if condation for two number with direction ex ( 50 North) then if they are same direction subract them and if they opposite add them ?

1 vue (au cours des 30 derniers jours)
x=50 E
z=3 W
  2 commentaires

Connectez-vous pour commenter.

Réponses (1)

John D'Errico
John D'Errico le 23 Déc 2021
Modifié(e) : John D'Errico le 23 Déc 2021
Numbers no not have a character component. They are just numbers. But you can always call East a POSITIVE direction. West is therefore a NEGATIVE direction. So apply a sign to the numbers, depending on your "direction" flag. Then you can just add the results.
Effectively, I am telling you to NOT have separate character flag. Make the sign of the number indicate the direction. So here, we wuld have
x = 50;
z = -3;
Now the composite result is trivial.
xplusz = x + z
xplusz = 47
And the net result is positive, so it is an easterly direction.
  4 commentaires

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by