views:

44

answers:

2

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.

+2  A: 

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
second
I Need to reduce the color space from 256 to 4 that I divid the image after read it by 64, when I try to compute the color histogram I found the color becom 5 not 4 because it round to nearest integer numbers.
zenab
ok, think i've found your problem, see edit
second
+1 for `double`.
Jonas
I try this and I get what I need...Thank you so much ..
zenab
np. do consider upvoting/accepting good answers to your questions, as this is considered good so etiquette. c.f. @Jonas comment to your question.
second
A: 

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.

Sanjay Manohar
I try the floor in my program also it round to nearest integer, plrase I need to get e.g:3.1=3 ; 3.2=3; 3.5=3; 3.7=3; 3.9=3
zenab
if this is the case, you are doing something wrong. please show us the output of `S(1,:)`. perhaps this is already rounded.
Sanjay Manohar