How do I split a text file at specified points?
조회 수: 6 (최근 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!