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.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 20 de En. de 2013
Editada: Azzi Abdelmalek el 20 de En. de 2013

4 votos

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

4 comentarios

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

Iniciar sesión para comentar.

Más respuestas (1)

Categorías

Más información sobre Files and Folders en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de En. de 2013

Respondida:

el 25 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by