MATLAB: I want to store the digits after the decimal point of the numbers stored in an array. How to do it

digital image processingimage processing

For eg. If one of my number is 1.23456789 then I want '234' out of it. I want only the 3 digits after the decimal point. Can you help me?

Best Answer

To get the digits in a scalar numeric:
>> x = 1.23456789;
>> N = 4;
>> n = fix(rem(x,1)*10^N)
n = 2345
then to convert this to a string:
>> s = sprintf('%.0f',n)
s = '2345'
and finally to get the digits in a numeric vector:
>> v = s-'0'
v = [2,3,4,5]