开发者

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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜