필터 지우기
필터 지우기

the integer part of the division

조회 수: 677 (최근 30일)
vaggelis vaggelakis
vaggelis vaggelakis 2012년 10월 4일
댓글: Royi Avital 2021년 4월 9일
hello everyone
how do i get the integer part of the output of a division i.e. 23/5=4 (and the remainder is 3)
  댓글 수: 2
Shashank Agarwal
Shashank Agarwal 2016년 11월 15일
floor(23/5)
Walter Roberson
Walter Roberson 2016년 11월 16일

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 4일
편집: Azzi Abdelmalek 2012년 10월 5일
fix(23/5) % integer part
rem(23,5) % remainder
%or
mod(23,5)
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 5일
It's fixed with fix
Royi Avital
Royi Avital 2021년 4월 9일
It works only for Float64 and Float32.
For integer types use idivide.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 10월 5일
Consider -23/5 (that is, the case of negative numbers.) Should that be -4 times 5 and remainder -3, or should it be -5 times 5 and remainder 2 ?
If you want the -4 version so that abs() of the "integer part" of -23/5 and 23/5 are the same, then use fix()
If you want the -5 version so that the remainder is always non-negative, then use floor()
You can use either fix() or floor() if you only have positive values, with floor() being preferred (more efficient, mathematically clearer)
Do not use round() even if you have only positive values. round(23/5) is 5, not 4.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by