Conversion from string to numbers within table

2 views (last 30 days)
Hi,
I have table with data (attached below), which I want to convert from string to numbers and store as the same table. Is there any fast way to do this?
In brief, I just want to change the format of data in table.

Answers (1)

Stephen23
Stephen23 on 12 Apr 2021
Edited: Stephen23 on 12 Apr 2021
Most likely you should fix the data importing, rather than messing around with converting strings.
load('data.mat')
T = varfun(@str2double,A_NFC);
T.Properties.VariableNames = A_NFC.Properties.VariableNames;
T.Time = datetime(A_NFC.Time,'InputFormat','dd.MM.yyyy')
T = 290×14 table
Time OTH_MFI_PLN OTH_MFI_FX OTH_MFI_TOT OTH_MFI_LOANS_PLN OTH_MFI_LOANS_FX OTH_MFI_LOANS_TOT OTH_C_PLN OTH_C_FX OTH_C_TOT MFI_L_C_PLN MFI_L_C_FX MFI_L_C_TOT ACC_INT ___________ ___________ __________ ___________ _________________ ________________ _________________ _________ ________ _________ ___________ __________ ___________ _______ 31-Jan-1997 45912 9617.1 55529 44099 9473.4 53572 1813.4 143.74 1957.2 45947 9617.1 55565 4795.2 28-Feb-1997 46740 9847.3 56588 44820 9698.6 54519 1919.8 148.64 2068.5 46775 9847.3 56623 5139.7 31-Mar-1997 47462 10511 57974 45483 10347 55829 1979.8 164.6 2144.4 47497 10511 58009 5203.3 30-Apr-1997 47953 11039 58991 45924 10861 56784 2029.3 178.14 2207.4 47988 11039 59026 5166.8 31-May-1997 47994 11559 59553 45932 11386 57318 2062.5 172.26 2234.7 48029 11559 59587 5474 30-Jun-1997 48616 12178 60794 46465 12003 58468 2150.2 175.7 2325.9 48655 12178 60833 5492.2 31-Jul-1997 48879 12955 61834 46705 12776 59481 2174.2 178.85 2353.1 48918 12955 61873 5643.3 31-Aug-1997 50083 13308 63392 47864 13117 60980 2219.7 191.61 2411.3 50123 13308 63431 5871.7 30-Sep-1997 51687 13711 65398 49435 13493 62928 2252 218.73 2470.7 51723 13711 65435 5747 31-Oct-1997 52222 14479 66701 49914 14245 64160 2307.7 233.32 2541.1 52258 14479 66737 5684 30-Nov-1997 54814 14603 69417 52447 14382 66828 2366.9 221.2 2588.1 54850 14603 69453 6004.4 31-Dec-1997 55057 14206 69264 52790 13990 66780 2266.9 216.65 2483.6 55096 14206 69303 4710.6 31-Jan-1998 57150 14898 72048 54852 14680 69532 2298.3 217.63 2515.9 57189 14898 72087 4788.8 28-Feb-1998 57817 15194 73011 55525 14970 70494 2292.4 224.58 2517 57856 15194 73050 5051.2 31-Mar-1998 58541 15563 74104 56157 15344 71501 2383.6 218.96 2602.5 58580 15563 74143 4922 30-Apr-1998 58547 16710 75257 56121 16475 72596 2425.6 234.78 2660.4 58586 16710 75296 4809.1
  1 Comment
Joanna Przeworska
Joanna Przeworska on 13 Apr 2021
Dear Stephen,
Thank you for your help. I will follow your suggestion and try to improve the import of data, first and if it is not working, use your solution.
Kind regards,
JP

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!