using matlab fileread function for some portion of text data

조회 수: 11 (최근 30일)
sermet OGUTCU
sermet OGUTCU 2021년 8월 23일
답변: Simon Chan 2021년 8월 23일
data = regexp(fileread(full_file_name),'\n','split');
end_of_header_line = find(contains(data,'* '));
I find the row number of the end of header part section in text file using the above codes. The end of header part section always situated in the beginning parts of the text file. Is there a way to use fileread with only the some portions of text file (for example from the first line to 50th line) insted of the whole text file?
If this is not possible, is there a way to read a few portion of text data for extracting the line number of specific string?

채택된 답변

Simon Chan
Simon Chan 2021년 8월 23일
Use function textscan to read the first 50 lines and the header will be stored on a cell array.
fid = fopen(fullfile(filepath,filename), 'r');
header = textscan(fid, '%[^,\n]', 50); % Read the first 50 header lines
fclose(fid);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by