Read Multiple lines of Mixed Data from DAT file
古いコメントを表示
Hi All,
I want to read data from a DAT file. The file has many lines with strings and numbers appearing at known positions. How can I read from a specific line number and column number on the dat file?
Best regards Rehan
回答 (1 件)
dpb
2016 年 1 月 3 日
Sequential files are, well, "sequential". There's not a way to read them as random-access; best one can do(*) is to read records sequentially until get where one wants to go and then parse the lines. Generally, one is better to read the full file content to memory and process there unless it's truly humongous.
(*) Under certain conditions, one can maneuver around by knowing record lengths and such, but similarly to the old saw of "if have to ask the price, you can't afford it" if one has to ask "how?", it's more complicated than you want to tackle.
doc fgetl
doc sscanf
doc textscanf
for the above. As you can see by looking at the number of questions regarding formatted input on the forum, if you attach a section of the particular file, people will generally show you how to write appropriate format strings to parse it. If it's just a mixture, read the examples carefully first; it's probably not too difficult...
2 件のコメント
Rehan Jamshed
2016 年 1 月 3 日
編集済み: dpb
2016 年 1 月 3 日
dpb
2016 年 1 月 3 日
OK, that's not very complicated but -- what is known a priori about the rest of the structure or is this it? That is, if the first record is '2' materials, are the following to records it or is there then some other set of "stuffs" yet to come? Does one know if parse the string for each of the N materials the size of the subsequent number of elements in the record or is that also unknown? Is the structure of the file always as shown or can the M numeric values/record be on more than a single record? "So few answers, so many questions..." :)
カテゴリ
ヘルプ センター および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!