How do I split a text file at specified points?
10 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Bob Thompson
2019 年 5 月 29 日
% 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.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!