Count the number of sequential fractional *nines* of a decimal number
More Answers (3)
If you have the Image Processing Toolbox you can use regionprops(). First I find all the 9's, including some you missed. Then I throw out single isolated 9's like there are in A(1) and A(2).
A = [0.999989023, 0.999994839, 0.999999751] str = sprintf('%1.10f ', A) nines = str == '9' % Get lengths of stretches of all 9's of 1 or more: measurements = regionprops(nines, 'Area'); B_all_nines = [measurements.Area] % Throw out any that are a single 9 B_multiple_nines = B_all_nines; % Make a copy B_multiple_nines(B_all_nines==1) =  % Delete 1's
Of course you could compact that down to about 2 or 3 lines of code but I just made it super explicit so you can follow what it's doing. It shows:
B_all_nines = 4 1 5 1 6 B_multiple_nines = 4 5 6