Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to check divisibility?

Asked by Caped Crusader on 20 Jan 2013

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.

0 Comments

Caped Crusader

Products

No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek on 20 Jan 2013
Edited by Azzi Abdelmalek on 20 Jan 2013
Accepted answer
a=3;
b=2;
out=~rem(a,b)*a/b

4 Comments

Azzi Abdelmalek on 20 Jan 2013
 ~mod(a,b) 

is fine

mod and rem are the same when a and b have the same sign

Caped Crusader on 20 Jan 2013

Thanks ,it works!

Caped Crusader on 20 Jan 2013

However, I used rem(a,b) format after checking the help files and it worked. Anyway thank you very much.

Azzi Abdelmalek

Contact us