Create formatted file using regular expressions

1 view (last 30 days)
I have an unformatted text file with data for 45 variables. The text file reads in a continuous line and some variables are not separated by any delimiter. I want to create a formatted text file that can easily be read into a matrix or table.
The attached file contains just one set of variables. How would one use regular expressions (or any function) to create a formatted file. For example: The first 4 numbers are the S/N value, the next 8 are the date,the next 8 places are the time followed by 2 spaces and then 3 letters for the data descriptor and so on.

Answers (1)

Pawel Jastrzebski
Pawel Jastrzebski on 13 Mar 2018
Edited: Pawel Jastrzebski on 13 Mar 2018
Quick fix for you would be to use Matlab's in-built Import Tool and generate the function that you can later use to import your data (provided they're always structured in the same way!):
You will see that the Import Tool will allow you to:
  • choose the default output, i.e. table (see 1)
  • and also detects the data type being imported (yellow highlight)
Now that you have your data imported, you can extract from the table the info that you want:
There are some variables which you will need to extract from the table and break down further (Imported table has 41 values and you mentioned 45 variables). I suspect these are:
  • Variable 1
  • Variable 5
But for others, just extract the data from the table into the row vector according to your own scheme i.e.:

Community Treasure Hunt

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

Start Hunting!