Create formatted file using regular expressions

1 Ansicht (letzte 30 Tage)
David du Preez
David du Preez am 13 Mär. 2018
Bearbeitet: Pawel Jastrzebski am 13 Mär. 2018
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.

Antworten (1)

Pawel Jastrzebski
Pawel Jastrzebski am 13 Mär. 2018
Bearbeitet: Pawel Jastrzebski am 13 Mär. 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.:

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by