필터 지우기
필터 지우기

Floor function for int8

조회 수: 8 (최근 30일)
Alexander Brodsky
Alexander Brodsky 2011년 8월 1일
I want to round down (floor) variable defined as int8 without converting to double !
for example: a=int8(8.6);
I want the result will equal to 8 instead of 9. Is there way to do or it impossible (without converting to double) ? The reason I need it, because I work with large matrix (25000x25000) of int8.
Thanks Alex
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 8월 1일
To check the circumstances: do you have something like
int8(86) ./ int8(10)
and you want the result to be int8(8) instead of int8(9) ?
Alexander Brodsky
Alexander Brodsky 2011년 8월 1일
exactly !

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

채택된 답변

Mike Hosea
Mike Hosea 2011년 8월 1일
Using your later example,
idivide(a,4,'floor')
does what you want there. I prefer to make both arguments integers of the same type, so I would probably have written
idivide(a,int8(4),'floor').
Note that the default option for idivide is 'fix', which might be what you want. Obviously, 'floor' and 'fix' are the same for non-negative quotients. -- Mike
  댓글 수: 3
Jan
Jan 2011년 8월 1일
@Mike: Thanks! I've learned a new command.
Mike Hosea
Mike Hosea 2011년 8월 2일
You're welcome. :) As I read the question and my response again, I think I should have made it more clear that both arguments need to be integers of the same type in order to avoid a cast to double inside of IDIVIDE.

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

추가 답변 (2개)

Paulo Silva
Paulo Silva 2011년 8월 1일
a=int8(floor(8.6))
  댓글 수: 1
Alexander Brodsky
Alexander Brodsky 2011년 8월 1일
sorry, my false for bad explanation.
new example:
a=int8(3);
a1=a/4;
I want a1 to be 0.

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


Sean de Wolski
Sean de Wolski 2011년 8월 1일
A = int8(magic(10));
B = int8(5);
idx = (mod(A,B)>(B/2)); %elements that need to be reduced.
C = A./B;
C(idx) = C(idx)-1;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by