Clear Filters
Clear Filters

How do I split a text file at specified points?

10 views (last 30 days)
Hi,
The text file I want to split into several files is of the following format:
$logE_b4
1 -2.705351823 41.20420904 1019.694408
2 -2.705336056 41.20422133 1019.888748
3 -2.705316622 41.20423859 1019.4342
4 -2.705258211 41.20426163 1019.306503
$logE_b6l
31 -2.705282293 41.20410169 1023.670194
32 -2.705316372 41.20405454 1023.15101
33 -2.70534887 41.20400166 1022.14706
34 -2.705389111 41.20394017 1020.771686
$logE_b6u
62 -2.705099405 41.20418307 1022.253319
63 -2.705171225 41.20413981 1024.090526
I now want to split it into several files at the $ sign and give it the filename after the $, e.g. logE_b4.
Can somebody please help me?

Accepted Answer

Bob Thompson
Bob Thompson on 29 May 2019
% Load the file
file = fileread('mytextfile.txt');
% Split the data at $
data = regexp(file,'.logE','split');
You may end up with an extra empty cell or two, but that should do what you're looking for.

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!