Search code examples
matlabmatrixmatlab-table

How to determine the number of digits of a number in a table


I am trying to determine the number of digits of a number in a table. For example if I have a table like this:

   4    200   50  1236
  69     54  285     1
1458      2   69   555

The answer would be

1 3 2 4
2 2 3 1 
4 1 2 3

I used to be able to do this with this code

strlength(num2str(ADCPCRUM2(i,2)))

but then my input was numeric, and not a table.

How do I determine the length of a number in a table?


Solution

  • floor(log10(A)) does this. log10() basically counts the number of digits before/behind the decimal separator where the most significant number is.

    When using this on a table, a simple call to table2array() should solve it.

    Caveat: this only works for integers; for non-integer inputs it would get a lot more involved.