MATLAB: Determine the first digit of each element of Fibonacci Sequence.

fibonacci sequence

Using your favorite programing language (Matlab) compute the first 1000 elements of the Fibonacci sequence f(n) =f(n−1) +f(n−2) where f(1) = f(2) = 1. Determine the first digit of each element .
Here, I can find the 1000 element easily using the Fibonacci function. But I am not sure how to the get the first digit of the fist 1000 element. Any suggestion will be appriciated. Thanks

Best Answer

str2double(cellfun(@(x)x(1),arrayfun(@(x)num2str(x),fibonacci(1:1000),'UniformOutput',false),'UniformOutput',false));
I think the above provides you with an array of the first digits of the fibonacci numbers up to 1000.