Hi, I need to check whether two numbers are divisible or not. But how can I do that in Matlab? e.g. Matlab gives 1.5 for 3/2 but I need to get 3/2 = 0 and 4/2 =2.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 20 Jan 2013
Modifié(e) : Azzi Abdelmalek le 20 Jan 2013

4 votes

a=3;
b=2;
out=~rem(a,b)*a/b

4 commentaires

Jurgen
Jurgen le 20 Jan 2013
or :
~mod(a/b,1)
will return 1 if divisble, zero if not.
Azzi Abdelmalek
Azzi Abdelmalek le 20 Jan 2013
Modifié(e) : Azzi Abdelmalek le 20 Jan 2013
~mod(a,b)
is fine
mod and rem are the same when a and b have the same sign
Caped Crusader
Caped Crusader le 20 Jan 2013
Thanks ,it works!
Caped Crusader
Caped Crusader le 20 Jan 2013
However, I used rem(a,b) format after checking the help files and it worked. Anyway thank you very much.

Connectez-vous pour commenter.

Plus de réponses (1)

Catégories

En savoir plus sur Files and Folders dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by