Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Obtain output from a text file
1 回表示 (過去 30 日間)
古いコメントを表示
Hi all,
May I ask how do I read from a text file. The text file are mostly in binary and have a string known as DICT.
I need to output the data that is after the word DICT.
0 件のコメント
回答 (1 件)
Walter Roberson
2014 年 1 月 3 日
fid = fopen('Filename goes here', 'r');
fread(fid, NumberOfBytesToSkip); %eg you know DICT is at byte #17409
rest_of_file = fread(fid, inf, 'char');
fclose(fid);
If you do not know where the DICT is located, the easiest method is going to depend upon the size of the file and the amount of memory you can spare.
Do you want from 'DICT' on to end of file, or to end of line ?
Note: if the file contains binary then by definition it is not a text file; it may, though, be a binary file that in part contains text data.
2 件のコメント
Walter Roberson
2014 年 1 月 3 日
filetext = fileread('Filename goes here');
dict_str = regexp(filetext, '(?:DICT).*', 'match');
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!