Create formatted file using regular expressions
显示 更早的评论
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
2018-3-13
编辑:Pawel Jastrzebski
2018-3-13
0 个投票
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.:

类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!