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.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 20일
편집: Azzi Abdelmalek 2013년 1월 20일

4 개 추천

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

댓글 수: 4

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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jitesh Kumar
Jitesh Kumar 2018년 9월 25일

2 개 추천

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

카테고리

도움말 센터File Exchange에서 Files and Folders에 대해 자세히 알아보기

질문:

2013년 1월 20일

답변:

2018년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by