MATLAB: Insert comma/point in a number


I have a temperature data in a char format without comma or point to divide the decimal and I want to insert a point after the second number (staring from the left):
char= 225800 and I want t=22.58
Can someone help me, please?
Thank you

Best Answer

  • I am not certain what you are doing.
    I assume ‘char’ is a character vector. If so, this will work:
    char = '225800';
    t = str2double(char)*1E-4 % Double-Precision Numeric
    tstr = sprintf('%.2f', t) % Character Array
    t =
    tstr =