MATLAB: Reading large data set from text file & separating to individual column

matrixmatrix manipulation

Hello, I have a text file in foll. format:
1950/05/21 04:00:00 1.7100 1 1
1950/05/21 05:00:00 1.5500 1 1
1950/05/21 06:00:00 1.4000 1 1
1950/05/21 07:00:00 1.2200 1 1
I need to separate it to individual column elements. The desired output is as below:
1950 05 21 04 1.71 1 1
1950 05 21 05 1.55 1 1
1950 05 21 06 1.40 1 1
1950 05 21 07 1.22 1 1
Please suggest codes for this. Thanks

Best Answer

  • Read in your data and then:
    dummy = '1950/05/21 04:00:00 1.7100 1 1';
    result = regexprep(dummy,'[\s/:]+',' ')
    If you just want to edit a text file like that, there probably are better tools than Matlab for that. grep, for instance.