text file with multiple section of headers
4 ビュー (過去 30 日間)
古いコメントを表示
I have a txt file data like bellow:(multiple section and each section with different column of data)
u v w p q
1 2 3 4 5
.
.
.
1 1 1 1 1
uu uv vv
4 3 8
.
.
.
1 1 1
I want to load each section of these set of data for plotting using fopen,textscan. How can I each section without calling fopen multiple time.
1 件のコメント
dpb
2022 年 9 月 4 日
"... without calling fopen multiple time."
As documented, textscan leaves the filepointer at the location of the last point read when either the number of items requested is satisfied or the conversion fails or reaches end of file. There's no need to close/reopen the file for multiple calls/reads.
BUT, with an irregular file structure such as that with variable number of variables in some records and no repeating pattern, it'll be very difficult to find a sequential format expression to keep the file pointer in synch and pick up for the next dataset. I think this is one that will be more well suited to simply use fgetl to read a line at a time and parse each record in turn. Or, use readlines (R2020b needed) to read the entire file into memory and do the same parsing except in memory.
The pasted data looks to have a lot of extra white space; hard to know what the real file really looks like -- attach it directly (or a representative portion if it is large).
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!