필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Obtain output from a text file

조회 수: 1 (최근 30일)
Derick Wong
Derick Wong 2014년 1월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
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.

답변 (1개)

Walter Roberson
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
Derick Wong
Derick Wong 2014년 1월 3일
편집: Derick Wong 2014년 1월 3일
The DICT is located near to the end of the text file, I need to read from DICT onward, which mean from DICT to the end of file.
I don't know where the DICT is located, but I do know it is from the last few lines in the text file.
The text file is in 10110101... and this goes on for hundred of lines because it is output from a huffman. Now I need to decode it by first reading the file.
I am not sure if I can count the number of bytes because the binary is in hundred of lines.
Walter Roberson
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!

Translated by