zenab
zenab

Reputation: 159

trunc the integer number from real number using matlab

please, any one help me to trunct the integer number from real number without any round to nearest integers in matlab ,e.g: if i have 255/64=3.98 I need just 3 not 4. I used fix in my program but not work. my cod is:

S=imread('image0286.jpg')/64; 
   disp(fix(S);

this give me the output after rounds the elements of S to the nearest integers not cut the integer.

Upvotes: 2

Views: 9424

Answers (2)

Sanjay Manohar
Sanjay Manohar

Reputation: 7026

floor(x) does this, though beware of negative numbers.

but fix should work too.

Also note that imread might return a byte array or int array rather than floats. so your division might be int-division, and automatically truncate without the need for fix or floor.

Upvotes: 0

second
second

Reputation: 28637

fix does do what you want.

>>fix(255/64)
    ans =
          3

maybe some other part of your code isn't doing what you think it is doing. could you post more code and your expected and real output

EDIT: Imread returns the values as uint8, and division in this class seems to carry out the rounding you don't want. try recasting to double before dividing

S = double(imread('image0286.jpg'))/64

Upvotes: 4

Related Questions