Create formatted file using regular expressions

1 回表示 (過去 30 日間)
David du Preez
David du Preez 2018 年 3 月 13 日
編集済み: Pawel Jastrzebski 2018 年 3 月 13 日
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.

回答 (1 件)

Pawel Jastrzebski
Pawel Jastrzebski 2018 年 3 月 13 日
編集済み: Pawel Jastrzebski 2018 年 3 月 13 日
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.:

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by