I want to implement a version of Benford's law (http://en.wikipedia.org/wiki/Benford%27s_law) that basically asks for the first digit of a number to do analysis on the distribution.
1934---> 1
0.04 ---> 4
-56 ---> 5
How do you do this in MATLAB?
function res = first_digit(number)
number = abs(number);
res = floor(number / (10 ^ floor(log10(number))));
end
It works for all real numbers (see gnovice's comment for an extreme case)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With