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.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 20 Jan. 2013
Bearbeitet: Azzi Abdelmalek am 20 Jan. 2013

4 Stimmen

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

4 Kommentare

Jurgen
Jurgen am 20 Jan. 2013
or :
~mod(a/b,1)
will return 1 if divisble, zero if not.
Azzi Abdelmalek
Azzi Abdelmalek am 20 Jan. 2013
Bearbeitet: Azzi Abdelmalek am 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 am 20 Jan. 2013
Thanks ,it works!
Caped Crusader
Caped Crusader am 20 Jan. 2013
However, I used rem(a,b) format after checking the help files and it worked. Anyway thank you very much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jitesh Kumar
Jitesh Kumar am 25 Sep. 2018

2 Stimmen

a=5; b=1; rem(a,b)=4

Kategorien

Mehr zu Files and Folders finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by